package com.gesee.zyspps.activity;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.AMap.OnCameraChangeListener;
import com.amap.api.maps2d.AMap.OnMapClickListener;
import com.amap.api.maps2d.AMap.OnMapScreenShotListener;
import com.amap.api.maps2d.AMap.OnMarkerClickListener;
import com.amap.api.maps2d.AMap.OnMarkerDragListener;
import com.amap.api.maps2d.CameraUpdate;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.LocationSource.OnLocationChangedListener;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.UiSettings;
import com.amap.api.maps2d.model.BitmapDescriptor;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.maps2d.model.MyLocationStyle;
import com.amap.api.maps2d.model.Polyline;
import com.amap.api.maps2d.model.PolylineOptions;
import com.gesee.zys.R;
import com.gesee.zyspps.ZSApplication;
import com.gesee.zyspps.adapter.DialogAdapter;
import com.gesee.zyspps.adapter.ExistenceProjectAdater;
import com.gesee.zyspps.adapter.MainSpinnerAdapter;
import com.gesee.zyspps.adapter.MessageAdater;
import com.gesee.zyspps.adapter.ShowBigTypeAdater;
import com.gesee.zyspps.adapter.ShowTypeAdater;
import com.gesee.zyspps.db.CmsDbNum;
import com.gesee.zyspps.db.CmsFeature;
import com.gesee.zyspps.db.CmsLine;
import com.gesee.zyspps.db.CmsPicture;
import com.gesee.zyspps.db.CmsPipelineField;
import com.gesee.zyspps.db.CmsPoints;
import com.gesee.zyspps.db.CmsPointsDao.Properties;
import com.gesee.zyspps.db.CmsPointsName;
import com.gesee.zyspps.db.CmsPointsNameDao;
import com.gesee.zyspps.db.CmsSpecialLine;
import com.gesee.zyspps.utils.ExcelUtils;
import com.gesee.zyspps.utils.IntentUtil;
import com.gesee.zyspps.utils.LogUtil;
import com.gesee.zyspps.utils.NetWorkUtils;
import com.gesee.zyspps.utils.PointLineUtil;
import com.gesee.zyspps.utils.StringUtil;
import com.gesee.zyspps.utils.ToastUtil;
import com.gesee.zyspps.utils.Utils;
import com.gesee.zyspps.widgets.CustomCircleView;
import com.gesee.zyspps.widgets.MaterialDialog;
import com.gesee.zyspps.widgets.MyListView;

/**
 * 
 * @ClassName: MainActivity
 * @Description: TODO(首页)
 * @author fujianxiong
 * @date 2015年8月11日 下午3:29:10
 * 
 */
public class MainActivity extends BaseActivity implements OnClickListener, LocationSource, AMapLocationListener, OnMapScreenShotListener
{
    // 定位相关
    private Button xinjian, caidan, dakai, guanbi;
    private List<LatLng> latLonList = new ArrayList<LatLng>();

    private String[] mItems;
    private Spinner spinner;
    private MainSpinnerAdapter spinnerAdapter, bigspinnerAdapter;
    private ArrayAdapter<String> arrayAdapter;

    private AMap aMap;
    private MapView mapView;
    private UiSettings mUiSettings;
    private OnLocationChangedListener mListener;
    private AMapLocationClient mlocationClient;
    private AMapLocationClientOption mLocationOption;

    private Button shiliuBei, baBei, siBei, yiBei;

    // UI相关
    boolean isFirstLoc = true;// 是否首次定位
    // private MaterialDialog removeLinedialog;
//    private MaterialDialog dialog;
    // private MaterialDialog updateDialog;
    // private MaterialDialog removePointDialog;

    private String mapNo;
    private ExistenceProjectAdater adapter;
    private List setList;
    private List<LatLng> lllist = new ArrayList<LatLng>();
    private List<LatLng> linePointList = new ArrayList<LatLng>();
    private List<LatLng> isHasList = new ArrayList<LatLng>();
    private ImageView drawPan, drawPoint, drawLine, drawMove, drawInsert, drawInfo, drawDelete;

    private String requestLocation;

    private Spinner bigspinner;
    private String selectSubCode;
    private String bigName;

    private boolean isDrawPan = false;
    private boolean isDrawPoint = false;
    private boolean isDrawLine = false;
    private boolean isDrawMove = false;
    private boolean isDrawInsert = false;
    private boolean isDrawInfo = false;
    private boolean isDrawDelete = false;

    private String cityName = "";
    private int progessValue = 0;
    private float zooSize = (float) 19.0;
    private ImageView ivCompass;
    private Button showTypeBtn,showTypeBigBtn;
    private List<LatLng> insertPointList = new ArrayList<LatLng>();
    
    private int beishu = 1;
    private int sbPoint = 15;
    private float sbLine = 1;
    private float sbFontSize = 4.0f;
    private int bbPoint = 15;
    private float bbLine = 0.5f;
    private float bbFontSize = 4.0f;
    private int slPoint = 15;
    private float slLine = 0.25f;
    private float slFontSize = 4.0f;
    private int ybPoint = 15;
    private float ybLine = 1;
    private float ybFontSize = 12.0f;
    
    private Map<String,String> selectMap = new HashMap<String,String>();
    private Map<String,String> selectBigMap = new HashMap<String,String>();
    private List samllList;

    // 导出数据
    private File file;
    private ArrayList<ArrayList<String>> pointList;
    private ArrayList<ArrayList<String>> lineList;
    private String[] pointsTitle =
    { "物探点号", "井底埋深", "管线类型", "附属物", "特征", "管点编号小标", "井盖规格", "井盖材质", "井盖尺寸", "井筒深度", "井室尺寸", "淤堵情况", "管偏井编号", "道路名称", "权属单位", "建设年代", "符号旋转角度", "图幅号", "探测单位", "探测日期", "工程名称", "测区名称", "街道名称", "小区名称",
            "社区名称", " 探测人员", "X坐标", "y坐标", "备注", "井室类型", "探测时水深", "探查时泥深", "检查井等级", "检查井照片编号" };

    private String[] linesTitle =
    { "管线长度", "起始物探点号", "终止物探点号", "起始埋深", "终止埋深", "管线类型", "埋设方式", "材质", "管径或断面尺寸", "套管或管沟尺寸", "压力", "电压",
            "流向", "电缆条数", "总孔数", "已用孔数", "权属单位名称", "建设年代", "道路名称", "起点管偏", "终点管偏", "所属街道", "所属社区",
            "所属小区", "测区名称", "探测单位", "探测日期", "工程名称", "探测人员", "备注", "电缆条数", "已用孔数", "总孔数", "录像编号1", "录像编号2" };

    private MaterialDialog removePointDialog, removeLinedialog, updateLineDialog, updatePointDialog,typeDialog,typeBigDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        selectMap.put("ALL", "全部");
        // mCurrentMode = LocationMode.NORMAL;
        List<CmsPointsName> list = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().orderAsc(com.gesee.zyspps.db.CmsPointsNameDao.Properties.Sort).list();
        if (list.size() <= 0 || list == null)
        {
            DataInitCmsPointsName.initCmsPointName();
        }

        List<CmsPipelineField> listField = ZSApplication.getDaoSession("zyspps-db").getCmsPipelineFieldDao().queryBuilder().orderAsc(com.gesee.zyspps.db.CmsPipelineFieldDao.Properties.Sort).list();
        if (listField.size() <= 0 || listField == null)
        {
            DataInitFiled.initFiled();
        }

        List<CmsFeature> listFeature = ZSApplication.getDaoSession("zyspps-db").getCmsFeatureDao().queryBuilder().orderAsc(com.gesee.zyspps.db.CmsFeatureDao.Properties.Sort).list();
        if (listFeature.size() <= 0 || listFeature == null)
        {
            DataInitTeZhengFuShu.initTeZhengFuShu();
        }

        List<CmsPicture> listPicture = ZSApplication.getDaoSession("zyspps-db").getCmsPictureDao().queryBuilder().list();
        if (listPicture.size() <= 0 || listPicture == null)
        {
            DatInitPicture.initDataPicture();
        }

        // MapStatus ms = new MapStatus.Builder().overlook(-30).build();
        findView();
        initView();
        removePointDialog = new MaterialDialog(context, "提示", "确定删除此管点么？");
        updatePointDialog = new MaterialDialog(context, "提示", "确定修改此管点属性么？");
        removeLinedialog = new MaterialDialog(context, "提示", "确定删除此线么？");
        updateLineDialog = new MaterialDialog(context, "提示", "确定修改此线属性么？");
        mapView.onCreate(savedInstanceState);// 此方法必须重写
    }

    private void findView()
    {
        mapView = (MapView) findViewById(R.id.map);
        spinner = (Spinner) findViewById(R.id.spinner);
        drawPan = (ImageView) findViewById(R.id.drawPan);
        drawPoint = (ImageView) findViewById(R.id.drawPoint);
        drawLine = (ImageView) findViewById(R.id.drawLine);
        drawMove = (ImageView) findViewById(R.id.drawMove);
        drawInsert = (ImageView) findViewById(R.id.drawInsert);
        drawInfo = (ImageView) findViewById(R.id.drawInfo);
        drawDelete = (ImageView) findViewById(R.id.drawDelete);
        bigspinner = (Spinner) findViewById(R.id.bigspinner);
        ivCompass = (ImageView) findViewById(R.id.ivCompass);
        caidan = (Button) findViewById(R.id.caidan);
        showTypeBtn = (Button) findViewById(R.id.showTypeBtn);
        showTypeBigBtn = (Button) findViewById(R.id.showTypeBigBtn);
        showTypeBigBtn.setOnClickListener(this);
        shiliuBei = (Button) findViewById(R.id.shiliuBei);
        baBei = (Button) findViewById(R.id.baBei);
        siBei = (Button) findViewById(R.id.siBei);
        yiBei = (Button) findViewById(R.id.yiBei);
    }

    private void initView()
    {
        pointList = new ArrayList<ArrayList<String>>();
        lineList = new ArrayList<ArrayList<String>>();
        ZSApplication.getInstance().setConfig("compass", "compass");
        if (aMap == null)
        {
            aMap = mapView.getMap();
            aMap.moveCamera(CameraUpdateFactory.zoomTo(18));// 设置默认级别
            mUiSettings = aMap.getUiSettings();
            setUpMap();
            setSpinner();
            String compass = ZSApplication.getInstance().getConfig("compass");
            if (StringUtil.isEmpty(compass))
            {
                ivCompass.setVisibility(View.GONE);
            }

            drawPan.setOnClickListener(this);
            drawPoint.setOnClickListener(this);
            drawLine.setOnClickListener(this);
            drawMove.setOnClickListener(this);
            drawInsert.setOnClickListener(this);
            drawInfo.setOnClickListener(this);
            drawDelete.setOnClickListener(this);
            showTypeBtn.setOnClickListener(this);

            firstOpenProject();
            
            caidan.setOnClickListener(new OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    // TODO Auto-generated method stub
                    Runtime runtime = Runtime.getRuntime();
                    try
                    {
                        runtime.exec("input keyevent " + KeyEvent.KEYCODE_MENU);
                    }
                    catch (IOException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });

            baBei.setOnClickListener(new OnClickListener()
            {

                @Override
                public void onClick(View v)
                {

                	Log.e("zoom", aMap.getCameraPosition().zoom+"");
                	boolean isTrue = isOpenProject();
                    if (isTrue != true)
                    {
                        return;
                    }
                	if(aMap.getCameraPosition().zoom == 19){
                		picSize(bbPoint,bbLine,bbFontSize);
                		mapView.setScaleX(8.0f);
                        mapView.setScaleY(8.0f);
                        beishu = 8;
                	}
                    
                }
            });

            siBei.setOnClickListener(new OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                	boolean isTrue = isOpenProject();
                    if (isTrue != true)
                    {
                        return;
                    }
                	if(aMap.getCameraPosition().zoom == 19){
                		picSize(sbPoint,sbLine,sbFontSize);
                        mapView.setScaleX(4.0f);
                        mapView.setScaleY(4.0f);
                        beishu = 4;
                	}
                	
                	
                }
            });

            shiliuBei.setOnClickListener(new OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    // TODO Auto-generated method stub
                	boolean isTrue = isOpenProject();
                    if (isTrue != true)
                    {
                        return;
                    }
                	if(aMap.getCameraPosition().zoom == 19){
                		picSize(slPoint,slLine,slFontSize);
                		mapView.setScaleX(16.0f);
                        mapView.setScaleY(16.0f);
                        beishu = 16;
                	}
                    
                }
            });

            yiBei.setOnClickListener(new OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    // TODO Auto-generated method stub
                	boolean isTrue = isOpenProject();
                    if (isTrue != true)
                    {
                        return;
                    }
                	picSize(ybPoint,ybLine,ybFontSize);
                    mapView.setScaleX(1.0f);
                    mapView.setScaleY(1.0f);
                    beishu = 1;
                }
            });
        }
    }
    
    public void setSize(int point ,float line,float fontSize,List<CmsPoints> pointList,List<CmsLine> lineList,List<CmsSpecialLine> specialLineLis){
    	if (pointList.size() > 0)
        {
            for (int i = 0; i < pointList.size(); i++)
            {
                double latitude = pointList.get(i).getD_X();
                double longitude = pointList.get(i).getD_Y();
                String subname = pointList.get(i).getExpNO();
                String smallName = pointList.get(i).getPCode();
                String fsw = pointList.get(i).getSubsid();
                LatLng latlon = new LatLng(latitude, longitude);
                isHasList.add(latlon);

                List<CmsPointsName> pointNameList = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(smallName)).build().list();
                if (pointNameList.size() == 0)
                {
                    ToastUtil.show(context, subname + "出错");
                    return;
                }
                String bigName = pointNameList.get(0).getParCode();
                String bigNameColor = pointNameList.get(0).getPointsColor();

                List<CmsPicture> picList = ZSApplication.getDaoSession("zyspps-db").getCmsPictureDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsPictureDao.Properties.ParCode.eq(bigName), com.gesee.zyspps.db.CmsPictureDao.Properties.FeatureName.eq(fsw)).build().list();

                String picName = null;
                for (int j = 0; j < picList.size(); j++)
                {
                    picName = picList.get(j).getPictureName();
                }

                // 设置标注物的图片
                View overView = LayoutInflater.from(context).inflate(R.layout.over_view, null);
                ImageView iv_overImage = (ImageView) overView.findViewById(R.id.iv_overImage);
                
                GradientDrawable d = (GradientDrawable) getResources().getDrawable(R.drawable.point_bg);//得到drawable资源文件.
                d.setColor(Color.parseColor(bigNameColor));//设置颜色
                iv_overImage.setBackgroundDrawable(d);
                
                ViewGroup.LayoutParams ll = iv_overImage.getLayoutParams();
                ll.width = point;
                ll.height = point;
                iv_overImage.setLayoutParams(ll);
                TextView tv_name = (TextView) overView.findViewById(R.id.tv_name);
                tv_name.setText(subname);
                tv_name.setTextSize(fontSize);
                tv_name.setTextColor(Color.parseColor(bigNameColor));

//                ApplicationInfo appInfo = getApplicationInfo();
//                if (picList.size() > 0)
//                {
//                    // 得到application对象
//                    int resID = getResources().getIdentifier(picName, "drawable", appInfo.packageName);
//                    iv_overImage.setImageResource(resID);
//                }
//                else
//                {
//                    int resID = getResources().getIdentifier(bigName.toLowerCase(), "drawable", appInfo.packageName);
//                    iv_overImage.setImageResource(resID);
//                }

                BitmapDescriptor bitmap = BitmapDescriptorFactory.fromView(overView);
                // 构建MarkerOption，用于在地图上添加Marker
                MarkerOptions options;
                options = new MarkerOptions().position(latlon).icon(bitmap).title(subname);
                options.anchor(0.3f, 0.85f);
                // 在地图上添加Marker，并显示
                aMap.addMarker(options);
            }
        }
        if (lineList.size() > 0)
        {
            for (int i = 0; i < lineList.size(); i++)
            {
                List<LatLng> showLineList = new ArrayList<LatLng>();
                String startPoint = lineList.get(i).getS_Point();
                String endPoint = lineList.get(i).getE_Point();

                CmsPoints points = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(startPoint)).build()
                        .list().get(0);
                String subName = points.getPCode();
                CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(subName))
                        .build().list().get(0);

                String lineColor = pointName.getPointsColor();
                LatLng latlng = new LatLng(points.getD_X(), points.getD_Y());

                CmsPoints points1 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(endPoint)).build()
                        .list().get(0);
                LatLng latlng1 = new LatLng(points1.getD_X(), points1.getD_Y());
                showLineList.add(latlng);
                showLineList.add(latlng1);
                linePointList.addAll(showLineList);
                aMap.addPolyline((new PolylineOptions()).width(line).add(showLineList.get(0), showLineList.get(1)).color(Color.parseColor(lineColor)));
            }
        }
        if (specialLineLis.size() > 0)
        {
            for (int i = 0; i < specialLineLis.size(); i++)
            {
                String startName = specialLineLis.get(i).getPCode();
                CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(startName))
                        .build().list().get(0);
                String lineColor = pointName.getPointsColor();

                double specialStartLatitude = specialLineLis.get(i).getStart_X();
                double specialStartLongitude = specialLineLis.get(i).getStart_Y();
                double specialStopLatitude = specialLineLis.get(i).getStop_X();
                double specialStopLongitude = specialLineLis.get(i).getStop_Y();

                LatLng startLatLng = new LatLng(specialStartLatitude, specialStartLongitude);
                LatLng stopLatLng = new LatLng(specialStopLatitude, specialStopLongitude);
        		aMap.addPolyline((new PolylineOptions()).width(line).add(startLatLng, stopLatLng).color(Color.parseColor(lineColor)));
            }
        }
    }
    
    public void picSize(int point ,float line,float fontSize){
    	// TODO Auto-generated method stub
    	aMap.clear();
    	List<CmsPoints> pointList = new ArrayList<CmsPoints>();
        List<CmsLine> lineList = new ArrayList<CmsLine>();
        List<CmsSpecialLine> cmsSpecialLinelist = new ArrayList<CmsSpecialLine>();
        if(selectMap!=null&&selectMap.size()>0){
        	if(selectMap.containsKey("ALL")){
        		
                List<CmsPoints> pointAllList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().loadAll();
                List<CmsLine> lineAllList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
                List<CmsSpecialLine> cmsSpecialLineAlllist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().loadAll();
                //loadPointOrLine(pointAllList, lineAllList, cmsSpecialLineAlllist);
                setSize(point,line,fontSize,pointAllList,lineAllList,cmsSpecialLineAlllist);
        	}else{
        		for(String key : selectMap.keySet()){
    				List<CmsPoints> pList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.PCode.eq(key)).build().list();
    				List<CmsLine> lList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().queryBuilder().where(com.gesee.zyspps.db.CmsLineDao.Properties.PCode.eq(key)).build().list();
    				List<CmsSpecialLine> slist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().queryBuilder()
                            .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.PCode.eq(key)).build().list();
    				pointList.addAll(pList);
    				lineList.addAll(lList);
    				cmsSpecialLinelist.addAll(slist);
    			}
        		setSize(point,line,fontSize,pointList,lineList,cmsSpecialLinelist);
    			//loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
        	}
			
		}
        
    }

    private void setUpMap()
    {
        // mUiSettings.setCompassEnabled(true);
        mUiSettings.setZoomGesturesEnabled(true);
        // 自定义系统定位小蓝点
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.location_marker));// 设置小蓝点的图标
        myLocationStyle.strokeColor(Color.BLACK);// 设置圆形的边框颜色
        myLocationStyle.radiusFillColor(Color.argb(100, 0, 0, 180));// 设置圆形的填充颜色
        // myLocationStyle.anchor(int,int)//设置小蓝点的锚点
        myLocationStyle.strokeWidth(1.0f);// 设置圆形的边框粗细
        aMap.setMyLocationStyle(myLocationStyle);
        aMap.setLocationSource(this);// 设置定位监听
        aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
        aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
        // aMap.setMyLocationType()
    }

    private void firstOpenProject()
    {
        String daName = ZSApplication.getInstance().getConfig("newDBName");
        if (StringUtil.isNotEmpty(daName))
        {
            final List<CmsPoints> pointList = ZSApplication.getDaoSession(daName).getCmsPointsDao().loadAll();
            final List<CmsLine> lineList = ZSApplication.getDaoSession(daName).getCmsLineDao().loadAll();
            List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().loadAll();
            loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
        }
    }

    public void dataChange(String parCode)
    {
        // 根据大类去获取小类数据
        List<CmsPointsName> smalllist = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.ParCode.eq(parCode)).list();
        setList = new ArrayList();
        //selectMap.clear();
        if (ZSApplication.getInstance().getConfig("biaoming").equals("2") || ZSApplication.getInstance().getConfig("biaoming").equals("null"))
        {
            for (int i = 0; i < smalllist.size(); i++)
            {
                setList.add(smalllist.get(i).getSubCode());
            }
        }
        // 添加到小类下拉框中
        spinnerAdapter.addData(setList);
        spinner.setSelection(0);
        selectSubCode = smalllist.get(0).getSubCode();
        mapNo = setList.get(0).toString();
        setList.add(0, "全部");
        //selectMap.put("ALL", "全部");
    }

    private void setSpinner()
    {
        // 获取大类数据
        List<CmsPointsName> list = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().orderAsc(com.gesee.zyspps.db.CmsPointsNameDao.Properties.Sort).list();
        List bigtList = new ArrayList();
        for (int i = 0; i < list.size(); i++)
        {
            int a = 0;
            if (bigtList != null && bigtList.size() > 0)
            {
                for (int j = 0; j < bigtList.size(); j++)
                {

                    if (bigtList.get(j).toString().equals(list.get(i).getParCode()))
                    {
                        break;
                    }
                    else
                    {
                        a = a + 1;
                    }
                }
            }

            if (a == bigtList.size())
            {
                bigtList.add(list.get(i).getParCode());
            }

        }
        ArrayAdapter parCodeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bigtList);
        parCodeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // 显示大类数据
        bigspinner.setAdapter(parCodeAdapter);

        spinnerAdapter = new MainSpinnerAdapter(this);
        spinner.setAdapter(spinnerAdapter);
        // 根据大类数据获得小类数据 显示在下拉框
        bigName = bigtList.get(0).toString();
        dataChange(bigtList.get(0).toString());

        // 大类点击后小类数据跟着切换
        bigspinner.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View arg1, int position, long arg3)
            {
                // TODO Auto-generated method stub
                bigName = parent.getItemAtPosition(position).toString();
                ZSApplication.getInstance().setConfig("BigName", bigName);
                // List<CmsPointsName> smalllist =
                // ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.ParCode.eq(bigtList.get(0).toString())).list();
                spinnerAdapter.cleanData();
                dataChange(bigName);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });

        spinner.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                mapNo = parent.getItemAtPosition(position).toString();
                selectSubCode = parent.getItemAtPosition(position).toString();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });
    }

    private void setDrawPan()
    {
        boolean isTrue = isOpenProject();
        if (isTrue == true)
        {
            mUiSettings.setScrollGesturesEnabled(true);
        }
    }

    /**
     * 
     * @Title: setMapMaker
     * @Description: TODO(设置标记物)
     * @author fujianxiong
     * @param isTrue
     * @throws
     */
    private void setMapMaker()
    {
        boolean isTrue = isOpenProject();
        if (isTrue != true)
        {
            return;
        }
        aMap.setOnMapClickListener(new OnMapClickListener()
        {

            @Override
            public void onMapClick(LatLng latLng)
            {
                // TODO Auto-generated method stub
                // 获取经纬度
                if (isDrawPoint)
                {
                    double latitude = latLng.latitude;
                    double longitude = latLng.longitude;

                    // 遍历所有的射线,返回符合条件的射线点的名字。
                    String getSpeciaLinePointNameStr = PointLineUtil.getLineIsOnePoint(latLng,beishu);
                    String getSpeciaLinePointName = null;
                    double getSpeciaLinePointStartLatitude = 0;
                    double getSpeciaLinePointStartLongitude = 0;
                    double getSpeciaLinePointStopLatitude = 0;
                    double getSpeciaLinePointStopLongitude = 0;
                    if (!"isNull".equals(getSpeciaLinePointNameStr))
                    {
                        ZSApplication.getInstance().setConfig("needDeleteSpeciaLine", "true");
                        String[] getSpeciaLinePointArray = getSpeciaLinePointNameStr.split(",");
                        getSpeciaLinePointName = getSpeciaLinePointArray[0];
                        getSpeciaLinePointStartLatitude = Double.parseDouble(getSpeciaLinePointArray[1]);
                        getSpeciaLinePointStartLongitude = Double.parseDouble(getSpeciaLinePointArray[2]);
                        getSpeciaLinePointStopLatitude = Double.parseDouble(getSpeciaLinePointArray[3]);
                        getSpeciaLinePointStopLongitude = Double.parseDouble(getSpeciaLinePointArray[4]);

                        LogUtil.e("Activity获取到的：" + getSpeciaLinePointName + "," + getSpeciaLinePointStartLatitude + "," + getSpeciaLinePointStartLongitude + "," + getSpeciaLinePointStopLatitude
                                + "," + getSpeciaLinePointStopLongitude);
                        
//                        ZSApplication.getInstance().setConfig("hebingdianxian", "yes");
                        
                        int size = 0;
                        
                        List<CmsPoints> pointsList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.PCode.eq(mapNo)).build().list();
                        int pointsSize = pointsList.size();
                        if (pointsSize == 0)
                        {
                            size = pointsList.size() + 1;
                        }
                        else
                        {
                            size = pointsList.get(pointsSize - 1).getMapNoNum() + 1;
                        }
                        
                        List<CmsSpecialLine> specialLineList = ZSApplication
                                .getDaoSession(ZSApplication.getInstance().getConfig("newDBName"))
                                .getCmsSpecialLineDao()
                                .queryBuilder()
                                .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_X.eq(getSpeciaLinePointStartLatitude),
                                        com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_Y.eq(getSpeciaLinePointStartLongitude),
                                        com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_X.eq(getSpeciaLinePointStopLatitude),
                                        com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_Y.eq(getSpeciaLinePointStopLongitude)).list();
//                        ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().delete(specialLineList.get(0));
                        CmsLine cmsLine = new CmsLine();
                        cmsLine.setS_Point(getSpeciaLinePointName);
                        cmsLine.setE_Point(mapNo+ size);
                        cmsLine.setPCode(mapNo);
                        ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().insert(cmsLine);
                        
//                        IntentUtil.startActivity(
//                                DrawPointActivity.class,
//                                new Intent().putExtra("mapNo", mapNo).putExtra("D_X", getSpeciaLinePointStopLatitude + "").putExtra("D_Y", getSpeciaLinePointStopLongitude + "")
//                                        .putExtra("subCode", selectSubCode));
                        
                        Intent intent = new Intent(context, DrawPointActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("mapNo", mapNo);
                        bundle.putString("D_X", getSpeciaLinePointStopLatitude + "");
                        bundle.putString("D_Y", getSpeciaLinePointStopLongitude + "");
                        bundle.putString("subCode", selectSubCode);
                        bundle.putSerializable("wocaonima", (Serializable) specialLineList);
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }
                    else
                    {
                        ZSApplication.getInstance().setConfig("needDeleteSpeciaLine", "false");
                        IntentUtil.startActivity(DrawPointActivity.class,
                                new Intent().putExtra("mapNo", mapNo).putExtra("D_X", latitude + "").putExtra("D_Y", longitude + "").putExtra("subCode", selectSubCode));
                    }

                }
            }
        });

    }

    public void setMaker(double latitude, double longitude, String name)
    {
        String fsw = ZSApplication.getInstance().getConfig("mapCurrentfsw");
        List<CmsPicture> picList = ZSApplication.getDaoSession("zyspps-db").getCmsPictureDao().queryBuilder()
                .where(com.gesee.zyspps.db.CmsPictureDao.Properties.ParCode.eq(bigName), com.gesee.zyspps.db.CmsPictureDao.Properties.FeatureName.eq(fsw)).build().list();
        String picName = null;

        List<CmsPointsName> pointNameList = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.ParCode.eq(bigName))
                .build().list();
        String bigNameColor = null;
        if (pointNameList.size() > 0)
        {
            bigNameColor = pointNameList.get(0).getPointsColor();
        }
        else
        {
            ToastUtil.show(context, "描点出错");
            return;
        }

        for (int i = 0; i < picList.size(); i++)
        {
            picName = picList.get(i).getPictureName();
        }

        LatLng latlon = new LatLng(latitude, longitude);
        latLonList.add(latlon);
        // 定义Maker坐标点
        isHasList.add(latlon);
        // 自定义标注物布局
        /*View overView = LayoutInflater.from(context).inflate(R.layout.over_view, null);
        TextView tv_name = (TextView) overView.findViewById(R.id.tv_name);
        ImageView iv_overImage = (ImageView) overView.findViewById(R.id.iv_overImage);
        tv_name.setText(name);
        tv_name.setTextColor(Color.parseColor(bigNameColor));*/
        
        View overView = LayoutInflater.from(context).inflate(R.layout.over_view, null);
        ImageView iv_overImage = (ImageView) overView.findViewById(R.id.iv_overImage);
        
        TextView tv_name = (TextView) overView.findViewById(R.id.tv_name);
        tv_name.setText(name);
        tv_name.setTextColor(Color.parseColor(bigNameColor));
        
        GradientDrawable d = (GradientDrawable) getResources().getDrawable(R.drawable.point_bg);
        d.setColor(Color.parseColor(bigNameColor));//设置颜色
        iv_overImage.setBackgroundDrawable(d);
        
        ViewGroup.LayoutParams ll = iv_overImage.getLayoutParams();
        if(beishu == 1){
        	ll.width = ybPoint;
            ll.height = ybPoint;
            tv_name.setTextSize(ybFontSize);
        }
        if(beishu == 4){
        	ll.width = sbPoint;
            ll.height = sbPoint;
            tv_name.setTextSize(sbFontSize);
        }
        if(beishu == 8){
        	ll.width = bbPoint;
            ll.height = bbPoint;
            tv_name.setTextSize(bbFontSize);
        }
        if(beishu == 16){
//        	ll.width = slPoint;
//            ll.height = slPoint;
            tv_name.setTextSize(slFontSize);
        }
        iv_overImage.setLayoutParams(ll);

        ApplicationInfo appInfo = getApplicationInfo();
        if (picList.size() > 0)
        {
            // 得到application对象
            int resID = getResources().getIdentifier(picName, "drawable", appInfo.packageName);
//            iv_overImage.setImageResource(resID);
        }
        else
        {
            int resID = getResources().getIdentifier(bigName.toLowerCase(), "drawable", appInfo.packageName);
//            iv_overImage.setImageResource(resID);
        }

        // 设置标注物的图片
        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromView(overView);
        // 构建MarkerOption，用于在地图上添加Marker
        MarkerOptions options = new MarkerOptions().position(latlon).icon(bitmap).title(name);
        // 在地图上添加Marker，并显示
        options.anchor(0.3f, 0.85f);
        aMap.addMarker(options);
        
        String needDeleteSpeciaLine = ZSApplication.getInstance().getConfig("needDeleteSpeciaLine");
        if ("true".equals(needDeleteSpeciaLine))
        {
            ZSApplication.getInstance().setConfig("needDeleteSpeciaLine","false");
            final List<CmsPoints> pointList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().loadAll();
            final List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
            List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().loadAll();
            loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
        }

        String insertPoint = ZSApplication.getInstance().getConfig("drawPoint");
        if ("true".equals(insertPoint))
        {
            // List<LatLng> lineList = new ArrayList<LatLng>();
            if (insertPointList != null && insertPointList.size() > 0)
            {
                List<CmsPoints> pointsList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                        .where(Properties.D_X.eq(insertPointList.get(0).latitude), Properties.D_Y.eq(insertPointList.get(0).longitude)).build().list();
                String startPoint1 = null;
                if (pointsList.size() > 0)
                {
                    startPoint1 = pointsList.get(0).getExpNO();
                }
                else
                {
                    ToastUtil.show(context, "插入点出错");
                    return;
                }

                List<CmsPoints> points2List = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                        .where(Properties.D_X.eq(insertPointList.get(1).latitude), Properties.D_Y.eq(insertPointList.get(1).longitude)).build().list();
                String startPoint2 = null;
                if (points2List.size() > 0)
                {
                    startPoint2 = points2List.get(0).getExpNO();
                }

                List<CmsPoints> points3List = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                        .where(Properties.D_X.eq(insertPointList.get(2).latitude), Properties.D_Y.eq(insertPointList.get(2).longitude)).build().list();
                String startPoint3 = null;
                if (points3List.size() > 0)
                {
                    startPoint3 = points3List.get(0).getExpNO();
                }

                List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsLineDao.Properties.S_Point.eq(startPoint1), com.gesee.zyspps.db.CmsLineDao.Properties.E_Point.eq(startPoint3)).build().list();

                ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().delete(lineList.get(0));
                // aMap.addPolyline((new
                // PolylineOptions()).width(2).add(insertPointList.get(0),
                // insertPointList.get(1)
                // ,insertPointList.get(2)).color(0xAAFF0000));

                CmsLine line = new CmsLine();
                line.setS_Point(startPoint1);
                line.setE_Point(startPoint2);
                ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().insert(line);

                CmsLine line2 = new CmsLine();
                line2.setS_Point(startPoint2);
                line2.setE_Point(startPoint3);
                ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().insert(line2);
                ZSApplication.getInstance().setConfig("drawPoint", "false");

                // linePointList.clear();
                insertPointList.clear();
                // isHasList.clear();
                aMap.clear();
                firstOpenProject();    
            }

        }

        ZSApplication.getInstance().setConfig("mapCurrentfsw", "");
        ZSApplication.getInstance().setConfig("mapCurrentD_X", "");
        ZSApplication.getInstance().setConfig("mapCurrentD_Y", "");
        ZSApplication.getInstance().setConfig("mapCurrentName", "");
    }

    private void setLine(String startPoint, String endPoint)
    {
        
        String isTrue = ZSApplication.getInstance().getConfig("delSp");
        if ("yes".equals(isTrue))
        {
            final List<CmsPoints> pointList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().loadAll();
            final List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
            List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().loadAll();
            loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
            ZSApplication.getInstance().setConfig("delSp","no");
            return;
        }
        
        List<LatLng> lineList = new ArrayList<LatLng>();
        List<CmsPoints> startList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(startPoint)).build()
                .list();
        String lineColor = null;
        for (int i = 0; i < startList.size(); i++)
        {
            double startLat = startList.get(i).getD_X();
            double startLon = startList.get(i).getD_Y();
            String subName = startList.get(i).getPCode();
            CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(subName)).build()
                    .list().get(0);
            lineColor = pointName.getPointsColor();
            LatLng latLon = new LatLng(startLat, startLon);
            lineList.add(latLon);
        }

        List<CmsPoints> endList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(endPoint)).build().list();
        for (int i = 0; i < endList.size(); i++)
        {
            double endLat = endList.get(i).getD_X();
            double endLon = endList.get(i).getD_Y();
            LatLng latLon = new LatLng(endLat, endLon);
            lineList.add(latLon);
        }
        linePointList.addAll(lineList);

        if(beishu == 1){
        	aMap.addPolyline((new PolylineOptions()).width(ybLine).add(lineList.get(0), lineList.get(1)).color(Color.parseColor(lineColor)));
        }
        if(beishu == 4){
        	aMap.addPolyline((new PolylineOptions()).width(sbLine).add(lineList.get(0), lineList.get(1)).color(Color.parseColor(lineColor)));
        }
        if(beishu == 8){
        	aMap.addPolyline((new PolylineOptions()).width(bbLine).add(lineList.get(0), lineList.get(1)).color(Color.parseColor(lineColor)));
        }
		if(beishu == 16){
			aMap.addPolyline((new PolylineOptions()).width(slLine).add(lineList.get(0), lineList.get(1)).color(Color.parseColor(lineColor)));
		}
        //aMap.addPolyline((new PolylineOptions()).width(4).add(lineList.get(0), lineList.get(1)).color(Color.parseColor(lineColor)));
        ZSApplication.getInstance().setConfig("startPoint", "");
        ZSApplication.getInstance().setConfig("endPoint", "");
    }

    private void loadPointOrLine(List<CmsPoints> pointList, List<CmsLine> lineList, List<CmsSpecialLine> specialLineLis)
    {
        if (pointList.size() > 0)
        {
            String projectState = ZSApplication.getInstance().getConfig("projectState");
            if ("open".equals(projectState))
            {
                LatLng ll = new LatLng(pointList.get(0).getD_X(), pointList.get(0).getD_Y());
                CameraUpdate cameraUpdate = CameraUpdateFactory.changeLatLng(ll);
                aMap.moveCamera(cameraUpdate);
                ZSApplication.getInstance().setConfig("projectState", "close");
            }

            for (int i = 0; i < pointList.size(); i++)
            {
                double latitude = pointList.get(i).getD_X();
                double longitude = pointList.get(i).getD_Y();
                String subname = pointList.get(i).getExpNO();
                String smallName = pointList.get(i).getPCode();
                String fsw = pointList.get(i).getSubsid();
                LatLng latlon = new LatLng(latitude, longitude);
                isHasList.add(latlon);

                List<CmsPointsName> pointNameList = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(smallName)).build().list();
                if (pointNameList.size() == 0)
                {
                    ToastUtil.show(context, subname + "出错");
                    return;
                }
                String bigName = pointNameList.get(0).getParCode();
                String bigNameColor = pointNameList.get(0).getPointsColor();

                List<CmsPicture> picList = ZSApplication.getDaoSession("zyspps-db").getCmsPictureDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsPictureDao.Properties.ParCode.eq(bigName), com.gesee.zyspps.db.CmsPictureDao.Properties.FeatureName.eq(fsw)).build().list();

                String picName = null;
                for (int j = 0; j < picList.size(); j++)
                {
                    picName = picList.get(j).getPictureName();
                }

                // 设置标注物的图片
                View overView = LayoutInflater.from(context).inflate(R.layout.over_view, null);
                ImageView iv_overImage = (ImageView) overView.findViewById(R.id.iv_overImage);
                TextView tv_name = (TextView) overView.findViewById(R.id.tv_name);
                tv_name.setText(subname);
                tv_name.setTextColor(Color.parseColor(bigNameColor));
                
                GradientDrawable d = (GradientDrawable) getResources().getDrawable(R.drawable.point_bg);
                d.setColor(Color.parseColor(bigNameColor));//设置颜色
                iv_overImage.setBackgroundDrawable(d);
                
                ViewGroup.LayoutParams ll = iv_overImage.getLayoutParams();
                if(beishu == 1){
                	ll.width = ybPoint;
                    ll.height = ybPoint;
                    tv_name.setTextSize(ybFontSize);
                }
                if(beishu == 4){
                	ll.width = sbPoint;
                    ll.height = sbPoint;
                    tv_name.setTextSize(sbFontSize);
                }
                if(beishu == 8){
                	ll.width = bbPoint;
                    ll.height = bbPoint;
                    tv_name.setTextSize(bbFontSize);
                }
                if(beishu == 16){
//                	ll.width = slPoint;
//                    ll.height = slPoint;
                    tv_name.setTextSize(slFontSize);
                }
                iv_overImage.setLayoutParams(ll);

//                ApplicationInfo appInfo = getApplicationInfo();
//                if (picList.size() > 0)
//                {
                    // 得到application对象
//                    int resID = getResources().getIdentifier(picName, "drawable", appInfo.packageName);
//                    iv_overImage.setImageResource(resID);
//                }
//                else
//                {
//                    int resID = getResources().getIdentifier(bigName.toLowerCase(), "drawable", appInfo.packageName);
//                    iv_overImage.setImageResource(resID);
//                }

                BitmapDescriptor bitmap = BitmapDescriptorFactory.fromView(overView);
                // 构建MarkerOption，用于在地图上添加Marker
                MarkerOptions options;
                options = new MarkerOptions().position(latlon).icon(bitmap).title(subname);
//                if (zooSize >= 18.0)
//                {
//                    options = new MarkerOptions().position(latlon).icon(bitmap).title(subname);
//                }
//                else
//                {
//                    options = new MarkerOptions().position(latlon).icon(bitmap).visible(false).title(subname);
//                }
                options.anchor(0.3f, 0.85f);
                // 在地图上添加Marker，并显示
                aMap.addMarker(options);
            }
        }
        if (lineList.size() > 0)
        {
            for (int i = 0; i < lineList.size(); i++)
            {
                List<LatLng> showLineList = new ArrayList<LatLng>();
                String startPoint = lineList.get(i).getS_Point();
                String endPoint = lineList.get(i).getE_Point();

                CmsPoints points = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(startPoint)).build()
                        .list().get(0);
                String subName = points.getPCode();
                CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(subName))
                        .build().list().get(0);

                String lineColor = pointName.getPointsColor();
                LatLng latlng = new LatLng(points.getD_X(), points.getD_Y());

                CmsPoints points1 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(endPoint)).build()
                        .list().get(0);
                LatLng latlng1 = new LatLng(points1.getD_X(), points1.getD_Y());
                showLineList.add(latlng);
                showLineList.add(latlng1);
                linePointList.addAll(showLineList);
                if(beishu == 1){
                	aMap.addPolyline((new PolylineOptions()).width(ybLine).add(showLineList.get(0), showLineList.get(1)).color(Color.parseColor(lineColor)));
                }
                if(beishu == 4){
                	aMap.addPolyline((new PolylineOptions()).width(sbLine).add(showLineList.get(0), showLineList.get(1)).color(Color.parseColor(lineColor)));
                }
                if(beishu == 8){
                	aMap.addPolyline((new PolylineOptions()).width(bbLine).add(showLineList.get(0), showLineList.get(1)).color(Color.parseColor(lineColor)));
                }
        		if(beishu == 16){
        			aMap.addPolyline((new PolylineOptions()).width(slLine).add(showLineList.get(0), showLineList.get(1)).color(Color.parseColor(lineColor)));
        		}
                //aMap.addPolyline((new PolylineOptions()).width(4).add(showLineList.get(0), showLineList.get(1)).color(Color.parseColor(lineColor)));
            }
        }
        if (specialLineLis.size() > 0)
        {
            for (int i = 0; i < specialLineLis.size(); i++)
            {
                String startName = specialLineLis.get(i).getPCode();
                CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(startName))
                        .build().list().get(0);
                String lineColor = pointName.getPointsColor();

                double specialStartLatitude = specialLineLis.get(i).getStart_X();
                double specialStartLongitude = specialLineLis.get(i).getStart_Y();
                double specialStopLatitude = specialLineLis.get(i).getStop_X();
                double specialStopLongitude = specialLineLis.get(i).getStop_Y();

                LatLng startLatLng = new LatLng(specialStartLatitude, specialStartLongitude);
                LatLng stopLatLng = new LatLng(specialStopLatitude, specialStopLongitude);
                //aMap.addPolyline((new PolylineOptions()).width(4).add(startLatLng, stopLatLng).color(Color.parseColor(lineColor)));
                if(beishu == 1){
                	aMap.addPolyline((new PolylineOptions()).width(ybLine).add(startLatLng, stopLatLng).color(Color.parseColor(lineColor)));
                }
                if(beishu == 4){
                	aMap.addPolyline((new PolylineOptions()).width(sbLine).add(startLatLng, stopLatLng).color(Color.parseColor(lineColor)));
                }
                if(beishu == 8){
                	aMap.addPolyline((new PolylineOptions()).width(bbLine).add(startLatLng, stopLatLng).color(Color.parseColor(lineColor)));
                }
        		if(beishu == 16){
        			aMap.addPolyline((new PolylineOptions()).width(slLine).add(startLatLng, stopLatLng).color(Color.parseColor(lineColor)));
        		}
            }
        }
    }

    /**
     * 
     * @Title: setMapLine
     * @Description: TODO(画线)
     * @author fujianxiong
     * @param isTrue
     * @throws
     */
    private void setMapLine()
    {

        boolean isTrue = isOpenProject();
        if (isTrue != true)
        {
            return;
        }

        aMap.setOnMarkerClickListener(new OnMarkerClickListener()
        {
            
            @Override
            public boolean onMarkerClick(Marker marker)
            {
                // TODO Auto-generated method stub
                double latitude = marker.getPosition().latitude;
                double longitude = marker.getPosition().longitude;
                
                lllist.add(new LatLng(latitude, longitude));
                if (lllist.size() == 2)
                {
                    String mapNameStart = PointLineUtil.getMapName(lllist.get(0), context,beishu);

                    if ("isNull".equals(mapNameStart))
                    {
                        ToastUtil.show(context, "线的起始位置附近没有可用点。");
                        lllist.clear();
                        return true;
                    }
                    String startName = mapNameStart.substring(0, 2);

                    // 判断线的终点附近有没有可用点。
                    String mapNameStop = PointLineUtil.getMapName(lllist.get(1), context,beishu);

                    // 附近没有
                    if ("isNull".equals(mapNameStop))
                    {
                        // 遍历所有的射线,返回符合条件的射线点的名字。
                        String getSpeciaLinePointNameStr = PointLineUtil.getLineIsOnePoint(lllist.get(1),beishu);
                        String getSpeciaLinePointName = null;
                        double getSpeciaLinePointStartLatitude = 0;
                        double getSpeciaLinePointStartLongitude = 0;
                        double getSpeciaLinePointStopLatitude = 0;
                        double getSpeciaLinePointStopLongitude = 0;
                        String speciaLinePointName = null;
                        if (!"isNull".equals(getSpeciaLinePointNameStr))
                        {
                            String[] getSpeciaLinePointArray = getSpeciaLinePointNameStr.split(",");
                            getSpeciaLinePointName = getSpeciaLinePointArray[0];
                            getSpeciaLinePointStartLatitude = Double.parseDouble(getSpeciaLinePointArray[1]);
                            getSpeciaLinePointStartLongitude = Double.parseDouble(getSpeciaLinePointArray[2]);
                            getSpeciaLinePointStopLatitude = Double.parseDouble(getSpeciaLinePointArray[3]);
                            getSpeciaLinePointStopLongitude = Double.parseDouble(getSpeciaLinePointArray[4]);

                            LogUtil.e("Activity获取到的：" + getSpeciaLinePointName + "," + getSpeciaLinePointStartLatitude + "," + getSpeciaLinePointStartLongitude + "," + getSpeciaLinePointStopLatitude
                                    + "," + getSpeciaLinePointStopLongitude);
                        }
                        // 根据射线的起始点，确定射线，或线段的颜色。
                        CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder()
                                .where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(startName)).build().list().get(0);
                        String lineColor = pointName.getPointsColor();
                        // 没有可用射线.
                        if ("isNull".equals(getSpeciaLinePointNameStr))
                        {
                            // 根据起始经纬度，返回起始经纬度附近可用点的经纬度。
                            LatLng newLatlng = PointLineUtil.getMapLatLng(lllist.get(0),beishu);
                            // 如果返回的经纬度为0.0，则说明画线的起始位置没有可用点，
                            // 如果返回的经纬度跟传入的经纬度不相同，则说明画线的起始位置有可用点，则画射线。
                            if("0.0".equals(newLatlng.latitude+""))
                            {
                                ToastUtil.show(context, "请重新画一次。");
                                lllist.clear();
                                return true;
                            }
                         // 画射线。
                            //aMap.addPolyline((new PolylineOptions()).width(4).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            if(beishu == 1){
                                aMap.addPolyline((new PolylineOptions()).width(ybLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            if(beishu == 4){
                                aMap.addPolyline((new PolylineOptions()).width(sbLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            if(beishu == 8){
                                aMap.addPolyline((new PolylineOptions()).width(bbLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            if(beishu == 16){
                                aMap.addPolyline((new PolylineOptions()).width(slLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            
                            mapView.invalidate();

                            // 保存射线到SQLite数据库。
                            CmsSpecialLine cmsSpecialLine = new CmsSpecialLine();
                            cmsSpecialLine.setExpNO(mapNameStart);
                            cmsSpecialLine.setPCode(startName);
                            cmsSpecialLine.setStart_X(newLatlng.latitude);
                            cmsSpecialLine.setStart_Y(newLatlng.longitude);
                            cmsSpecialLine.setStop_X(lllist.get(1).latitude);
                            cmsSpecialLine.setStop_Y(lllist.get(1).longitude);

                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().insert(cmsSpecialLine);
                            lllist.clear();
                            return true;
                        }
                        // 有可用射线.
                        else
                        {
                            // 先得到可用射线起始点的点号。
                            // getSpeciaLinePointName,及起始，终止坐标，删除射线。
                            // 再链接
                            if (!"isNull".equals(getSpeciaLinePointNameStr))
                            {
                                speciaLinePointName = getSpeciaLinePointName.substring(0, 2);
                                
                                List<CmsPointsName> c1 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(startName)).list();
                                List<CmsPointsName> c2 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(speciaLinePointName)).list();
                                /*if (!startName.equals(speciaLinePointName))
                                {
                                    ToastUtil.show(context, "不同类型的管点不能连线!");
                                    lllist.clear();
                                    return true;
                                }*/
                                if(c1!=null&&c2!=null){
                                	if(c1.size()>0&&c2.size()>0){
                                		if(!c1.get(0).getParCode().equals(c2.get(0).getParCode())){
                                			ToastUtil.show(context, "不同类型的管点不能连线!");
                                            lllist.clear();
                                            return true;
                                		}
                                	}
                                }
                            }

                            List<CmsSpecialLine> specialLineList = ZSApplication
                                    .getDaoSession(ZSApplication.getInstance().getConfig("newDBName"))
                                    .getCmsSpecialLineDao()
                                    .queryBuilder()
                                    .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_X.eq(getSpeciaLinePointStartLatitude),
                                            com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_Y.eq(getSpeciaLinePointStartLongitude),
                                            com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_X.eq(getSpeciaLinePointStopLatitude),
                                            com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_Y.eq(getSpeciaLinePointStopLongitude)).list();
//                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().delete(specialLineList.get(0));
//                            
//                            IntentUtil.startActivity(DrawLineActivity.class, new Intent().putExtra("startPoint", mapNameStart).putExtra("endPoint", getSpeciaLinePointName));
                            
                            Intent intent = new Intent(context, DrawLineActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putString("startPoint", mapNameStart);
                            bundle.putString("endPoint", getSpeciaLinePointName);
                            bundle.putSerializable("caonima", (Serializable) specialLineList);
                            intent.putExtras(bundle);
                            startActivity(intent);
                            ZSApplication.getInstance().setConfig("delSp","yes");
//                            CmsLine cmsLine = new CmsLine();
//                            cmsLine.setS_Point(mapNameStart);
//                            cmsLine.setE_Point(getSpeciaLinePointName);
//                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().insert(cmsLine);
//                            lllist.clear();
//                            isHasList.clear();
//                            aMap.clear();
//                            linePointList.clear();

                            return true;
                        }

                    }

                    String stopName = mapNameStop.substring(0, 2);

                    List<CmsPointsName> c1 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(startName)).list();
                            List<CmsPointsName> c2 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(stopName)).list();
                    // 判断点的类型。
                            if(c1!=null&&c2!=null){
                            	if(c1.size()>0&&c2.size()>0){
                            		if(!c1.get(0).getParCode().equals(c2.get(0).getParCode())){
                            			ToastUtil.show(context, "不同类型的管点不能连线!");
                                        lllist.clear();
                                        return true;
                            		}
                            	}
                            }
                    /*if (!startName.equals(stopName))
                    {
                        ToastUtil.show(context, "不同类型的管点不能连线!");
                        lllist.clear();
                        return true;
                    }*/

                    // 判断是否存在此线。
                    boolean isIdentical = PointLineUtil.getLineNameIsIdentical(mapNameStart, mapNameStop);
                    if (isIdentical)
                    {
                        ToastUtil.show(context, "已存在同名线段！");
                        lllist.clear();
                        return true;
                    }
                    
                    if (mapNameStart.equals(mapNameStop))
                    {
                        ToastUtil.show(context, "画线过短,请重新绘制线！");
                        lllist.clear();
                        return true;
                    }

                    // 画线。
//                    IntentUtil.startActivity(DrawLineActivity.class, new Intent().putExtra("startPoint", mapNameStart).putExtra("endPoint", mapNameStop));
                    Intent intent = new Intent(context, DrawLineActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("startPoint", mapNameStart);
                    bundle.putString("endPoint", mapNameStop);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    lllist.clear();
                }
                return true;
            }
        });
        
        aMap.setOnMapClickListener(new OnMapClickListener()
        {

            @Override
            public void onMapClick(LatLng latlng)
            {
                // TODO Auto-generated method stub
                if (!isDrawLine)
                {
                    return;
                }
                double latitude = latlng.latitude;
                double longitude = latlng.longitude;
                LogUtil.e("latitude:" + latitude + "===" + "longitude:" + longitude);

                lllist.add(latlng);
                LogUtil.e("数组长度：" + lllist.size());
                if (lllist.size() == 2)
                {
                    String mapNameStart = PointLineUtil.getMapName(lllist.get(0), context,beishu);

                    if ("isNull".equals(mapNameStart))
                    {
                        ToastUtil.show(context, "线的起始位置附近没有可用点。");
                        lllist.clear();
                        return;
                    }
                    String startName = mapNameStart.substring(0, 2);

                    // 判断线的终点附近有没有可用点。
                    String mapNameStop = PointLineUtil.getMapName(lllist.get(1), context,beishu);

                    // 附近没有
                    if ("isNull".equals(mapNameStop))
                    {
                        // 遍历所有的射线,返回符合条件的射线点的名字。
                        String getSpeciaLinePointNameStr = PointLineUtil.getLineIsOnePoint(lllist.get(1),beishu);
                        String getSpeciaLinePointName = null;
                        double getSpeciaLinePointStartLatitude = 0;
                        double getSpeciaLinePointStartLongitude = 0;
                        double getSpeciaLinePointStopLatitude = 0;
                        double getSpeciaLinePointStopLongitude = 0;
                        String speciaLinePointName = null;
                        if (!"isNull".equals(getSpeciaLinePointNameStr))
                        {
                            String[] getSpeciaLinePointArray = getSpeciaLinePointNameStr.split(",");
                            getSpeciaLinePointName = getSpeciaLinePointArray[0];
                            getSpeciaLinePointStartLatitude = Double.parseDouble(getSpeciaLinePointArray[1]);
                            getSpeciaLinePointStartLongitude = Double.parseDouble(getSpeciaLinePointArray[2]);
                            getSpeciaLinePointStopLatitude = Double.parseDouble(getSpeciaLinePointArray[3]);
                            getSpeciaLinePointStopLongitude = Double.parseDouble(getSpeciaLinePointArray[4]);

                            LogUtil.e("Activity获取到的：" + getSpeciaLinePointName + "," + getSpeciaLinePointStartLatitude + "," + getSpeciaLinePointStartLongitude + "," + getSpeciaLinePointStopLatitude
                                    + "," + getSpeciaLinePointStopLongitude);
                        }
                        // 根据射线的起始点，确定射线，或线段的颜色。
                        CmsPointsName pointName = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder()
                                .where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.SubCode.eq(startName)).build().list().get(0);
                        String lineColor = pointName.getPointsColor();
                        // 没有可用射线.
                        if ("isNull".equals(getSpeciaLinePointNameStr))
                        {
                            // 根据起始经纬度，返回起始经纬度附近可用点的经纬度。
                            LatLng newLatlng = PointLineUtil.getMapLatLng(lllist.get(0),beishu);
                            // 如果返回的经纬度为0.0，则说明画线的起始位置没有可用点，
                            // 如果返回的经纬度跟传入的经纬度不相同，则说明画线的起始位置有可用点，则画射线。
                            if("0.0".equals(newLatlng.latitude+""))
                            {
                                ToastUtil.show(context, "请重新画一次。");
                                lllist.clear();
                                return;
                            }
                         // 画射线。
                            //aMap.addPolyline((new PolylineOptions()).width(4).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            if(beishu == 1){
                                aMap.addPolyline((new PolylineOptions()).width(ybLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            if(beishu == 4){
                                aMap.addPolyline((new PolylineOptions()).width(sbLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            if(beishu == 8){
                                aMap.addPolyline((new PolylineOptions()).width(bbLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            if(beishu == 16){
                                aMap.addPolyline((new PolylineOptions()).width(slLine).add(newLatlng, lllist.get(1)).color(Color.parseColor(lineColor)));
                            }
                            
                            mapView.invalidate();

                            // 保存射线到SQLite数据库。
                            CmsSpecialLine cmsSpecialLine = new CmsSpecialLine();
                            cmsSpecialLine.setExpNO(mapNameStart);
                            cmsSpecialLine.setPCode(startName);
                            cmsSpecialLine.setStart_X(newLatlng.latitude);
                            cmsSpecialLine.setStart_Y(newLatlng.longitude);
                            cmsSpecialLine.setStop_X(lllist.get(1).latitude);
                            cmsSpecialLine.setStop_Y(lllist.get(1).longitude);

                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().insert(cmsSpecialLine);
                            lllist.clear();
                            return;
                        }
                        // 有可用射线.
                        else
                        {
                            // 先得到可用射线起始点的点号。
                            // getSpeciaLinePointName,及起始，终止坐标，删除射线。
                            // 再链接
                            if (!"isNull".equals(getSpeciaLinePointNameStr))
                            {
                                speciaLinePointName = getSpeciaLinePointName.substring(0, 2);
                                /*if (!startName.equals(speciaLinePointName))
                                {
                                    ToastUtil.show(context, "不同类型的管点不能连线!");
                                    lllist.clear();
                                    return;
                                }*/
                                List<CmsPointsName> c1 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(startName)).list();
                                        List<CmsPointsName> c2 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(speciaLinePointName)).list();
                                        /*if (!startName.equals(speciaLinePointName))
                                        {
                                            ToastUtil.show(context, "不同类型的管点不能连线!");
                                            lllist.clear();
                                            return true;
                                        }*/
                                        if(c1!=null&&c2!=null){
                                        	if(c1.size()>0&&c2.size()>0){
                                        		if(!c1.get(0).getParCode().equals(c2.get(0).getParCode())){
                                        			ToastUtil.show(context, "不同类型的管点不能连线!");
                                                    lllist.clear();
                                                    return;
                                        		}
                                        	}
                                        }
                            }

                            List<CmsSpecialLine> specialLineList = ZSApplication
                                    .getDaoSession(ZSApplication.getInstance().getConfig("newDBName"))
                                    .getCmsSpecialLineDao()
                                    .queryBuilder()
                                    .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_X.eq(getSpeciaLinePointStartLatitude),
                                            com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_Y.eq(getSpeciaLinePointStartLongitude),
                                            com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_X.eq(getSpeciaLinePointStopLatitude),
                                            com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_Y.eq(getSpeciaLinePointStopLongitude)).list();
//                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().delete(specialLineList.get(0));
                            
//                            IntentUtil.startActivity(DrawLineActivity.class, new Intent().putExtra("startPoint", mapNameStart).putExtra("endPoint", getSpeciaLinePointName));
                           
                            Intent intent = new Intent(context, DrawLineActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putString("startPoint", mapNameStart);
                            bundle.putString("endPoint", getSpeciaLinePointName);
                            bundle.putSerializable("caonima", (Serializable) specialLineList);
                            intent.putExtras(bundle);
                            startActivity(intent);
                            
                            ZSApplication.getInstance().setConfig("delSp","yes");
//                            CmsLine cmsLine = new CmsLine();
//                            cmsLine.setS_Point(mapNameStart);
//                            cmsLine.setE_Point(getSpeciaLinePointName);
//                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().insert(cmsLine);
//                            lllist.clear();
//                            isHasList.clear();
//                            aMap.clear();
//                            linePointList.clear();

                            return;
                        }

                    }

                    String stopName = mapNameStop.substring(0, 2);

                    // 判断点的类型。
                    List<CmsPointsName> c1 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(startName)).list();
                            List<CmsPointsName> c2 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(stopName)).list();
                    // 判断点的类型。
                            if(c1!=null&&c2!=null){
                            	if(c1.size()>0&&c2.size()>0){
                            		if(!c1.get(0).getParCode().equals(c2.get(0).getParCode())){
                            			ToastUtil.show(context, "不同类型的管点不能连线!");
                                        lllist.clear();
                                        return;
                            		}
                            	}
                            }
                    /*if (!startName.equals(stopName))
                    {
                        ToastUtil.show(context, "不同类型的管点不能连线!");
                        lllist.clear();
                        return;
                    }*/

                    // 判断是否存在此线。
                    boolean isIdentical = PointLineUtil.getLineNameIsIdentical(mapNameStart, mapNameStop);
                    if (isIdentical)
                    {
                        ToastUtil.show(context, "已存在同名线段！");
                        lllist.clear();
                        return;
                    }
                    
                    if (mapNameStart.equals(mapNameStop))
                    {
                        ToastUtil.show(context, "画线过短,请重新绘制线！");
                        lllist.clear();
                        return;
                    }

                    // 画线。
//                    IntentUtil.startActivity(DrawLineActivity.class, new Intent().putExtra("startPoint", mapNameStart).putExtra("endPoint", mapNameStop));
                    Intent intent = new Intent(context, DrawLineActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("startPoint", mapNameStart);
                    bundle.putString("endPoint", mapNameStop);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    lllist.clear();
                }
            }
        });
    }

    private void movePoint()
    {
        /**
         * 移动标注物
         */
        aMap.setOnMarkerClickListener(new OnMarkerClickListener()
        {

            @Override
            public boolean onMarkerClick(Marker marker)
            {
                // TODO Auto-generated method stub
                if (isDrawMove)
                {
                    // marker.remove();
                    marker.setDraggable(true);
                    final double latitude = marker.getPosition().latitude;
                    final double longitude = marker.getPosition().longitude;
                    String mapName = null;

                    List<CmsPoints> pointsList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                            .where(Properties.D_X.eq(latitude), Properties.D_Y.eq(longitude)).build().list();
                    for (int i = 0; i < pointsList.size(); i++)
                    {
                        mapName = pointsList.get(i).getExpNO();
                    }
                    ToastUtil.show(context, "选择了：" + mapName + ";请长按：" + mapName + "拖拽");
                    // BitmapDescriptor bitmap =
                    // BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
                    // marker.setIcon(bitmap);
                }
                return true;
            }
        });
        aMap.setOnMarkerDragListener(new OnMarkerDragListener()
        {

            @Override
            public void onMarkerDragStart(Marker marker)
            {

            }

            @Override
            public void onMarkerDragEnd(Marker marker)
            {
                // TODO Auto-generated method stub
                if (isDrawMove)
                {
                    double latitude = marker.getPosition().latitude;
                    double longitude = marker.getPosition().longitude;
                    
                    String title = marker.getTitle();

                    List<CmsPoints> pointsList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                            .where(Properties.ExpNO.eq(marker.getTitle())).build().list();
                    String mapName = null;
                    for (int i = 0; i < pointsList.size(); i++)
                    {
                        mapName = pointsList.get(i).getExpNO();
                        String mapD_X = latitude + "";
                        String mapD_Y = longitude + "";
                        int mapNoNum = pointsList.get(i).getMapNoNum();
                        String smallName = pointsList.get(i).getPCode();
                        String tezheng = pointsList.get(i).getFeature();
                        String fsw = pointsList.get(i).getSubsid();
                        String jdms = pointsList.get(i).getWDeep();
                        String jggg = pointsList.get(i).getMtype();
                        String jgcz = pointsList.get(i).getWcover();
                        String jgcc = pointsList.get(i).getMsize();
                        String jtsd = pointsList.get(i).getWdepth();
                        String jscc = pointsList.get(i).getHsize();
                        String qsdw = pointsList.get(i).getBCode();
                        String dlmc = pointsList.get(i).getRoadName();
                        /*
                         * String dlts = pointsList.get(i).getCableLines();
                         * String yyks = pointsList.get(i).getUseHole(); String
                         * zks = pointsList.get(i).getTotalHole();
                         */
                        String bz = pointsList.get(i).getRemark();
                        String ydqk = pointsList.get(i).getSblock();
                        String jslx = pointsList.get(i).getJslx();
                        String tcsns = pointsList.get(i).getTcsns();
                        String tcsss = pointsList.get(i).getTcsss();
                        String jcjdj = pointsList.get(i).getJcjdj();
                        String jcjzpbh = pointsList.get(i).getJcjzpbh();
                        long id = pointsList.get(i).getId();

                        CmsPoints points = new CmsPoints();
                        points.setId(id);
                        points.setExpNO(mapName);
                        points.setPCode(smallName);
                        points.setMapNoNum(mapNoNum);
                        points.setD_X(Double.parseDouble(mapD_X));
                        points.setD_Y(Double.parseDouble(mapD_Y));
                        points.setFeature(tezheng);
                        // points.setVisibility(kj);
                        points.setSubsid(fsw);
                        points.setWDeep(jdms);
                        points.setMtype(jggg);
                        points.setWcover(jgcz);
                        // points.setMsize(jgcc);
                        points.setWdepth(jtsd);
                        points.setHsize(jscc);
                        points.setBCode(qsdw);
                        points.setRoadName(dlmc);
                        /*points.setCableLines(dlts);
                        points.setUseHole(yyks);
                        points.setTotalHole(zks);*/
                        points.setRemark(bz);
                        points.setSblock(ydqk);
                        points.setJslx(jslx);
                        points.setTcsns(tcsns);
                        points.setTcsss(tcsss);
                        points.setJcjdj(jcjdj);
                        points.setJcjzpbh(jcjzpbh);
                        ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().updateInTx(points);
                    }
                    
                    List<CmsSpecialLine> special = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().queryBuilder()
                            .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.ExpNO.eq(title)).build().list();
                    
                    for (int j = 0; j < special.size(); j++)
                    {
                        long id = special.get(j).getId();
                        String ExpNO= special.get(j).getExpNO();
                        String PCode= special.get(j).getPCode();
                        double stop_X = special.get(j).getStop_X();
                        double stop_Y = special.get(j).getStop_Y();
                        
                        CmsSpecialLine specialLise = new CmsSpecialLine();
                        specialLise.setId(id);
                        specialLise.setExpNO(ExpNO);
                        specialLise.setPCode(PCode);
                        specialLise.setStart_X(latitude);
                        specialLise.setStart_Y(longitude);
                        specialLise.setStop_X(stop_X);
                        specialLise.setStop_Y(stop_Y);
                        ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().updateInTx(specialLise);
                    }

                    lllist.clear();
                    isHasList.clear();
                    aMap.clear();
                    linePointList.clear();
                    final List<CmsPoints> pointList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().loadAll();
                    final List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
                    List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().loadAll();

                    if (pointList.size() > 0)
                    {
                        loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
                    }
                    // mMapView
                }
            }

            @Override
            public void onMarkerDrag(Marker marker)
            {

            }
        });
    }

    private void updatePoint()
    {
        aMap.setOnMapClickListener(new OnMapClickListener()
        {

            @Override
            public void onMapClick(LatLng latLng)
            {
                // TODO Auto-generated method stub
                if (isDrawInfo)
                {
                    String pointInLine = PointLineUtil.getUpdatePointIntoLine(latLng, aMap);
                    if ("isNull".equals(pointInLine))
                    {
                        return;
                    }
                    else
                    {
                        String[] getSpeciaLinePointArray = pointInLine.split(",");
                        double getSpeciaLinePointStartLatitude = Double.parseDouble(getSpeciaLinePointArray[0]);
                        double getSpeciaLinePointStartLongitude = Double.parseDouble(getSpeciaLinePointArray[1]);
                        double getSpeciaLinePointStopLatitude = Double.parseDouble(getSpeciaLinePointArray[2]);
                        double getSpeciaLinePointStopLongitude = Double.parseDouble(getSpeciaLinePointArray[3]);

                        CmsPoints points = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                                .where(Properties.D_X.eq(getSpeciaLinePointStartLatitude), Properties.D_Y.eq(getSpeciaLinePointStartLongitude)).build().list().get(0);

                        CmsPoints points1 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                                .where(Properties.D_X.eq(getSpeciaLinePointStopLatitude), Properties.D_Y.eq(getSpeciaLinePointStopLongitude)).build().list().get(0);
                        updateLineDialog(points.getExpNO(), points1.getExpNO(), updateLineDialog);
                    }
                }

            }
        });

        aMap.setOnMarkerClickListener(new OnMarkerClickListener()
        {

            @Override
            public boolean onMarkerClick(final Marker marker)
            {
                // TODO Auto-generated method stub
                if (isDrawInfo)
                {
                    // 获取经纬度
                    final double latitude = marker.getPosition().latitude;
                    final double longitude = marker.getPosition().longitude;
                    List<CmsPoints> pointsNameList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                            .where(Properties.D_X.eq(latitude), Properties.D_Y.eq(longitude)).build().list();

                    double mapNoLatitude;
                    double mapNoLongitude;
                    LatLng latLng = null;
                    final LatLng newLatLng;
                    final String mapNo = pointsNameList.get(0).getPCode();
                    mapNoLatitude = pointsNameList.get(0).getD_X();
                    mapNoLongitude = pointsNameList.get(0).getD_Y();
                    latLng = new LatLng(mapNoLatitude, mapNoLongitude);
                    newLatLng = latLng;

                    updatePointDialog.setOnAcceptButtonClickListener(new OnClickListener()
                    {

                        @Override
                        public void onClick(View v)
                        {
                            marker.remove();
                            IntentUtil.startActivity(UpdatePointActivity.class, new Intent().putExtra("mapNo", mapNo).putExtra("D_X", latitude + "").putExtra("D_Y", longitude + ""));
                            for (int i = 0; i < isHasList.size(); i++)
                            {
                                LatLng ll = isHasList.get(i);
                                if (newLatLng == ll)
                                {
                                    isHasList.remove(i);
                                }
                            }
                            updatePointDialog.dismiss();
                        }
                    });
                    updatePointDialog.setOnCancelButtonClickListener(new OnClickListener()
                    {

                        @Override
                        public void onClick(View v)
                        {
                            updatePointDialog.dismiss();
                        }
                    });
                    updatePointDialog.show();
                    updatePointDialog.getButtonAccept().setText("确定");
                    updatePointDialog.getButtonCancel().setVisibility(View.GONE);
                }
                return true;
            }
        });
    }

    private void updateLineDialog(final String startPoint, final String endPoint, final MaterialDialog updateDialog)
    {
        updateDialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                IntentUtil.startActivity(UpdateLineActivity.class, new Intent().putExtra("startPoint", startPoint).putExtra("endPoint", endPoint));
                updateDialog.dismiss();
            }
        });
        updateDialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                updateDialog.dismiss();
            }
        });
        updateDialog.show();
        updateDialog.getButtonAccept().setText("确定");
        updateDialog.getButtonCancel().setVisibility(View.GONE);
    }

    private void removePointDialog(final Marker marker, final Double latitude, final Double longitude, final MaterialDialog removePointDialog)
    {
        removePointDialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                marker.remove();
                CmsPoints points = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                        .where(Properties.D_X.eq(latitude), Properties.D_Y.eq(longitude)).list().get(0);
                ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().delete(points);
                List<CmsLine> startList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsLineDao.Properties.S_Point.eq(points.getExpNO())).build().list();

                if (startList.size() > 0)
                {
                    for (int i = 0; i < startList.size(); i++)
                    {
                        ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().delete(startList.get(i));
                    }
                }

                List<CmsLine> endList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsLineDao.Properties.E_Point.eq(points.getExpNO())).build().list();

                if (endList.size() > 0)
                {
                    for (int i = 0; i < endList.size(); i++)
                    {
                        ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().delete(endList.get(i));
                    }
                }

                // List<CmsSpecialLine> specialLineList =
                // ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao()
                List<CmsSpecialLine> specialLineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_X.eq(latitude), com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_Y.eq(longitude)).list();

                for (int i = 0; i < specialLineList.size(); i++)
                {
                    ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().delete(specialLineList.get(i));
                }
                isHasList.clear();
                aMap.clear();
                final List<CmsPoints> pointList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().loadAll();
                final List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
                List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().loadAll();
                if (pointList.size() > 0)
                {
                    loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
                }
                removePointDialog.dismiss();
            }
        });
        removePointDialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                removePointDialog.dismiss();
            }
        });
        if (!removePointDialog.isShowing())
        {
            removePointDialog.show();
        }
        removePointDialog.getButtonAccept().setText("确定");
        removePointDialog.getButtonCancel().setVisibility(View.GONE);
    }

    private void removeLineDialog(final double getSpeciaLinePointStartLatitude, final double getSpeciaLinePointStartLongitude, final double getSpeciaLinePointStopLatitude,
            final double getSpeciaLinePointStopLongitude, final MaterialDialog removeLinedialog)
    {
        removeLinedialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                List<CmsSpecialLine> specialLineList = ZSApplication
                        .getDaoSession(ZSApplication.getInstance().getConfig("newDBName"))
                        .getCmsSpecialLineDao()
                        .queryBuilder()
                        .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_X.eq(getSpeciaLinePointStartLatitude),
                                com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Start_Y.eq(getSpeciaLinePointStartLongitude),
                                com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_X.eq(getSpeciaLinePointStopLatitude),
                                com.gesee.zyspps.db.CmsSpecialLineDao.Properties.Stop_Y.eq(getSpeciaLinePointStopLongitude)).list();
                if (specialLineList.size() > 0)
                {
                    ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().delete(specialLineList.get(0));
                }
                else
                {
                    List<CmsPoints> points = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                            .where(Properties.D_X.eq(getSpeciaLinePointStartLatitude), Properties.D_Y.eq(getSpeciaLinePointStartLongitude)).build().list();

                    List<CmsPoints> points1 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                            .where(Properties.D_X.eq(getSpeciaLinePointStopLatitude), Properties.D_Y.eq(getSpeciaLinePointStopLongitude)).build().list();
                    
                    if (points.size() > 0 && points1.size() > 0)
                    {
                        List<CmsLine> list1 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().queryBuilder()
                                .where(com.gesee.zyspps.db.CmsLineDao.Properties.S_Point.eq(points.get(0).getExpNO()),com.gesee.zyspps.db.CmsLineDao.Properties.E_Point.eq(points1.get(0).getExpNO())).build().list();
                        
                        List<CmsLine> list2 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().queryBuilder()
                                .where(com.gesee.zyspps.db.CmsLineDao.Properties.S_Point.eq(points1.get(0).getExpNO()),com.gesee.zyspps.db.CmsLineDao.Properties.E_Point.eq(points.get(0).getExpNO())).build().list();
                        
                        if (list1.size() > 0)
                        {
                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().delete(list1.get(0));
                        }
                        else if (list2.size() > 0)
                        {
                            ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().delete(list2.get(0));
                        }
                    }
                }
                

                removeLinedialog.dismiss();

                lllist.clear();
                isHasList.clear();
                aMap.clear();
                linePointList.clear();

                final List<CmsPoints> pointList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().loadAll();
                final List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
                List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsSpecialLineDao().loadAll();
                loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
            }
        });
        removeLinedialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                removeLinedialog.dismiss();
            }
        });
        if (!removeLinedialog.isShowing())
        {
            removeLinedialog.show();
        }
        removeLinedialog.getButtonAccept().setText("确定");
        removeLinedialog.getButtonCancel().setVisibility(View.GONE);
    }

    /**
     * 删除标注物
     * 
     * @param latitude
     * @param longitude
     */
    private void removePoint()// final double latitude, final double longitude
    {
        boolean isTrue = isOpenProject();
        if (isTrue != true)
        {
            return;
        }
        aMap.setOnMapClickListener(new OnMapClickListener()
        {

            @Override
            public void onMapClick(LatLng latLng)
            {
                // TODO Auto-generated method stub
                if (isDrawDelete)
                {
                    String pointInLine = PointLineUtil.getPointIntoLine(latLng, aMap);
                    if ("isNull".equals(pointInLine))
                    {
                        return;
                    }
                    else
                    {
                        String[] getSpeciaLinePointArray = pointInLine.split(",");
                        double getSpeciaLinePointStartLatitude = Double.parseDouble(getSpeciaLinePointArray[0]);
                        double getSpeciaLinePointStartLongitude = Double.parseDouble(getSpeciaLinePointArray[1]);
                        double getSpeciaLinePointStopLatitude = Double.parseDouble(getSpeciaLinePointArray[2]);
                        double getSpeciaLinePointStopLongitude = Double.parseDouble(getSpeciaLinePointArray[3]);
                        removeLineDialog(getSpeciaLinePointStartLatitude, getSpeciaLinePointStartLongitude, getSpeciaLinePointStopLatitude, getSpeciaLinePointStopLongitude, removeLinedialog);
                    }
                }
            }
        });
        aMap.setOnMarkerClickListener(new OnMarkerClickListener()
        {

            @Override
            public boolean onMarkerClick(final Marker marker)
            {
                // TODO Auto-generated method stub
                if (isDrawDelete) //
                {
                    final double latitude = marker.getPosition().latitude;
                    final double longitude = marker.getPosition().longitude;
                    removePointDialog(marker, latitude, longitude, removePointDialog);
                }
                return true;
            }
        });
    }

    /**
     * 
     * @Title: drawInsertPoint
     * @Description: TODO(插入点)
     * @author fujianxiong
     * @throws
     */
    private void drawInsertPoint()
    {
        boolean isTrue = isOpenProject();
        if (isTrue != true)
        {
            return;
        }

        if (isDrawInsert)
        {
            final List<CmsLine> lineList = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();

            LogUtil.e("TMD线："+ lineList.size());
            aMap.setOnMapClickListener(new OnMapClickListener()
            {

                @Override
                public void onMapClick(LatLng latLng)
                {
                    // TODO Auto-generated method stub
                    if (lineList.size() == 0)
                    {
                        ToastUtil.show(context, "当前工程不存在管线！");
                        return;
                    }
                    String pointInLine = PointLineUtil.getUpdatePointIntoLine(latLng, aMap);
                    if ("isNull".equals(pointInLine))
                    {
                        return;
                    }
                    else
                    {
                        ZSApplication.getInstance().setConfig("drawPoint", "true");
                        String[] getSpeciaLinePointArray = pointInLine.split(",");
                        double getSpeciaLinePointStartLatitude = Double.parseDouble(getSpeciaLinePointArray[0]);
                        double getSpeciaLinePointStartLongitude = Double.parseDouble(getSpeciaLinePointArray[1]);
                        double getSpeciaLinePointStopLatitude = Double.parseDouble(getSpeciaLinePointArray[2]);
                        double getSpeciaLinePointStopLongitude = Double.parseDouble(getSpeciaLinePointArray[3]);

                        CmsPoints points = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                                .where(Properties.D_X.eq(getSpeciaLinePointStartLatitude), Properties.D_Y.eq(getSpeciaLinePointStartLongitude)).build().list().get(0);

                        CmsPoints points1 = ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder()
                                .where(Properties.D_X.eq(getSpeciaLinePointStopLatitude), Properties.D_Y.eq(getSpeciaLinePointStopLongitude)).build().list().get(0);
                        List<CmsPointsName> c1 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(points.getPCode())).list();
                                List<CmsPointsName> c2 = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(CmsPointsNameDao.Properties.SubCode.eq(selectSubCode)).list();
                              
                                if(c1!=null&&c2!=null){
                                	if(c1.size()>0&&c2.size()>0){
                                		if(!c1.get(0).getParCode().equals(c2.get(0).getParCode())){
                                			ToastUtil.show(context, "不同类型的管点不能插入点!");
                                		}else{
                                			insertPointList.add(new LatLng(points.getD_X(), points.getD_Y()));
                                            insertPointList.add(latLng);
                                            insertPointList.add(new LatLng(points1.getD_X(), points1.getD_Y()));
                                            IntentUtil.startActivity(DrawPointActivity.class,
                                                    new Intent().putExtra("mapNo", mapNo).putExtra("D_X", latLng.latitude + "").putExtra("D_Y", latLng.longitude + "").putExtra("subCode", selectSubCode));
                                            LogUtil.e("mapNo:"+mapNo);
                                		}
                                	}
                                }
                        
                    }
                }
            });
        }

        // aMap.setOnPolylineClickListener(new OnPolylineClickListener()
        // {
        //
        // @Override
        // public void onPolylineClick(Polyline polyline)
        // {
        // // TODO Auto-generated method stub
        // ToastUtil.show(context, "嘿嘿~点中线了。");
        // polyline.remove();
        // ZSApplication.getInstance().setConfig("drawPoint", "true");
        // List<LatLng> latlngList = polyline.getPoints();
        // LatLng latlng = new LatLng(latitude, longitude);
        //
        // insertPointList.add(latlngList.get(0));
        // insertPointList.add(latlng);
        // insertPointList.add(latlngList.get(1));
        //
        // IntentUtil.startActivity(DrawPointActivity.class,
        // new Intent().putExtra("mapNo", mapNo).putExtra("D_X", latitude +
        // "").putExtra("D_Y", longitude + "").putExtra("subCode",
        // selectSubCode));
        // }
        // });

        // aMap.setOnMapClickListener(new OnMapClickListener()
        // {
        //
        // @Override
        // public void onMapClick(LatLng latLng)
        // {
        // // TODO Auto-generated method stub
        // // 获取添加点经纬度
        // if (isDrawInsert)
        // {
        // ZSApplication.getInstance().setConfig("drawPoint", "true");
        // double latitude = latLng.latitude;
        // double longitude = latLng.longitude;
        // LatLng latLon = new LatLng(latitude, longitude);
        //
        // List<CmsLine> lineList =
        // ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsLineDao().loadAll();
        //
        // List<Double> newDistance = new ArrayList<Double>();
        //
        // if (lineList.size() == 0)
        // {
        // ToastUtil.show(context, "当前工程不存在管线！");
        // return;
        // }
        //
        // for (int i = 0; i < lineList.size(); i++)
        // {
        // List<LatLng> showLineList = new ArrayList<LatLng>();
        // String startPoint = lineList.get(i).getS_Point();
        // String endPoint = lineList.get(i).getE_Point();
        // CmsPoints points =
        // ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(startPoint))
        // .build().list().get(0);
        // LatLng latlng = new LatLng(points.getD_X(), points.getD_Y());
        //
        // CmsPoints points1 =
        // ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(endPoint))
        // .build().list().get(0);
        // LatLng latlng1 = new LatLng(points1.getD_X(), points1.getD_Y());
        // showLineList.add(latlng);
        // showLineList.add(latlng1);
        // // LatLng newLatLon =
        // // SpatialRelationUtil.getNearestPointFromLine(showLineList,
        // // latLon);
        // //
        // // double distance = DistanceUtil.getDistance(latLon,
        // // newLatLon);
        // // newDistance.add(distance);
        // }
        //
        // double endDistance = Collections.min(newDistance);
        //
        // for (int i = 0; i < lineList.size(); i++)
        // {
        // List<LatLng> showLineList = new ArrayList<LatLng>();
        // String startPoint = lineList.get(i).getS_Point();
        // String endPoint = lineList.get(i).getE_Point();
        // CmsPoints points =
        // ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(startPoint))
        // .build().list().get(0);
        // LatLng latlng = new LatLng(points.getD_X(), points.getD_Y());
        //
        // CmsPoints points1 =
        // ZSApplication.getDaoSession(ZSApplication.getInstance().getConfig("newDBName")).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(endPoint))
        // .build().list().get(0);
        // LatLng latlng1 = new LatLng(points1.getD_X(), points1.getD_Y());
        // showLineList.add(latlng);
        // showLineList.add(latlng1);
        // // LatLng newLatLon =
        // // SpatialRelationUtil.getNearestPointFromLine(showLineList,
        // // latLon);
        // //
        // // double distance = DistanceUtil.getDistance(latLon,
        // // newLatLon);
        // // if (endDistance == distance)
        // // {
        // // insertPointList.add(latlng);
        // // insertPointList.add(newLatLon);
        // // insertPointList.add(latlng1);
        // // double newLatitude = newLatLon.latitude;
        // // double newLongitude = newLatLon.longitude;
        // // IntentUtil.startActivity(DrawPointActivity.class,
        // // new Intent().putExtra("mapNo", mapNo).putExtra("D_X",
        // // newLatitude + "").putExtra("D_Y", newLongitude +
        // // "").putExtra("subCode", selectSubCode));
        // // }
        // }
        // }
        // }
        // });
    }

    private void createProject()
    {
        View createProjectView = LayoutInflater.from(context).inflate(R.layout.create_project_dialog, null);
        final EditText et_project_name = (EditText) createProjectView.findViewById(R.id.et_project_name);

        final MaterialDialog dialog = new MaterialDialog(context, "新建工程", createProjectView);
        dialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                String projectName = et_project_name.getText().toString();
                if (StringUtil.isEmpty(projectName))
                {
                    ToastUtil.show(context, "项目名不能为空~");
                    return;
                }
                CmsDbNum dbNum = new CmsDbNum();
                dbNum.setDbName(projectName);
                ZSApplication.getDaoSession(projectName);
                ZSApplication.getDaoSession().getCmsDbNumDao().insert(dbNum);
                ZSApplication.getInstance().setConfig("newDBName", projectName);
                ZSApplication.getInstance().setConfig("isHasProject", "true");
                dialog.dismiss();
            }
        });
        dialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.show();
        dialog.getButtonAccept().setText("确定");
        dialog.getButtonCancel().setText("取消");
    }

    private void exportProject()
    {
        final List<CmsDbNum> dbList = ZSApplication.getDaoSession("zyspps-db").getCmsDbNumDao().loadAll();

        View openProjectView = LayoutInflater.from(context).inflate(R.layout.open_project_dialog, null);
        final MyListView listView = (MyListView) openProjectView.findViewById(R.id.listView);

        adapter = new ExistenceProjectAdater(context);
        adapter.setList(dbList);
        listView.setAdapter(adapter);

        final MaterialDialog dialog = new MaterialDialog(context, "可以导出的项目名", openProjectView);
        dialog.show();
        dialog.getButtonAccept().setVisibility(View.GONE);
        dialog.getButtonCancel().setVisibility(View.GONE);

        listView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                String daName = dbList.get(position).getDbName();
                initPoints(daName);
                initLines(daName);
                dialog.dismiss();
            }
        });
    }
    
    private void openProject()
    {
        final List<CmsDbNum> dbList = ZSApplication.getDaoSession("zyspps-db").getCmsDbNumDao().loadAll();

        View openProjectView = LayoutInflater.from(context).inflate(R.layout.open_project_dialog, null);
        final MyListView listView = (MyListView) openProjectView.findViewById(R.id.listView);

        adapter = new ExistenceProjectAdater(context);
        adapter.setList(dbList);
        listView.setAdapter(adapter);

        final MaterialDialog dialog = new MaterialDialog(context, "存在的工程文件名称", openProjectView);
        dialog.show();
        dialog.getButtonAccept().setVisibility(View.GONE);
        dialog.getButtonCancel().setVisibility(View.GONE);

        listView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                String daName = dbList.get(position).getDbName();
                ZSApplication.getInstance().setConfig("isHasProject", "true");
                ZSApplication.getInstance().setConfig("newDBName", daName);
                ZSApplication.getInstance().setConfig("projectState", "open");
                final List<CmsPoints> pointList = ZSApplication.getDaoSession(daName).getCmsPointsDao().loadAll();
                final List<CmsLine> lineList = ZSApplication.getDaoSession(daName).getCmsLineDao().loadAll();
                List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().loadAll();
                if (pointList.size() > 0)
                {
                    loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
                }
                dialog.dismiss();
            }
        });
    }

    private void searchPoint()
    {
        View createProjectView = LayoutInflater.from(context).inflate(R.layout.create_project_dialog, null);
        final EditText et_project_name = (EditText) createProjectView.findViewById(R.id.et_project_name);

        final MaterialDialog dialog = new MaterialDialog(context, "查找点号", createProjectView);
        dialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                String projectName = et_project_name.getText().toString();
                if (StringUtil.isEmpty(projectName))
                {
                    ToastUtil.show(context, "点号不能为空~");
                    return;
                }

                List<CmsPoints> pointsList = new ArrayList<CmsPoints>();

                String dbName = ZSApplication.getInstance().getConfig("newDBName");

                pointsList = ZSApplication.getDaoSession(dbName).getCmsPointsDao().queryBuilder().where(Properties.ExpNO.eq(projectName)).build().list();

                if (pointsList.size() == 0)
                {
                    ToastUtil.show(context, "此点号不存在");
                    return;
                }

                for (int i = 0; i < pointsList.size(); i++)
                {
                    double lat = pointsList.get(i).getD_X();
                    double lon = pointsList.get(i).getD_Y();
                    LatLng ll = new LatLng(lat, lon);

                    // 设置标注物的图片
                    BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
                    // 构建MarkerOption，用于在地图上添加Marker
                    MarkerOptions options = new MarkerOptions().position(ll).icon(bitmap).draggable(false);
                    // 在地图上添加Marker，并显示
                    options.anchor(0.3f, 0.85f);
                    aMap.addMarker(options);

                    // 改变地图状态
                    CameraUpdate cameraUpdate = CameraUpdateFactory.changeLatLng(ll);
                    aMap.moveCamera(cameraUpdate);
                    // ToastUtil.show(context, projectName+"已中心显示");
                }

                dialog.dismiss();
            }
        });
        dialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.show();
        dialog.getButtonAccept().setText("确定");
        dialog.getButtonCancel().setText("取消");
    }

    private void messageDialog()
    {
        boolean isTrue = NetWorkUtils.checkEnable(context);
        String title = null;
        if (isTrue)
        {
            title = NetWorkUtils.getLocalIpAddress(context);
        }
        else
        {
            title = "获取ip出错";
        }

        View messageView = LayoutInflater.from(context).inflate(R.layout.message_dialog, null);

        Button btnAll = (Button) messageView.findViewById(R.id.btnAll);
        Button btnCancel = (Button) messageView.findViewById(R.id.btnCancel);
        MyListView listView = (MyListView) messageView.findViewById(R.id.listView);

        // 获取焦点
        btnAll.setFocusable(true);
        btnAll.setFocusableInTouchMode(true);
        btnAll.requestFocus();

        final List<CmsPoints> poiList = new ArrayList<CmsPoints>();

        for (int i = 0; i < 10; i++)
        {
            CmsPoints point = new CmsPoints();
            point.setId((long) i);
            point.setExpNO(i + "");
            poiList.add(point);
        }

        final MessageAdater adapter = new MessageAdater(poiList, context);

        adapter.setList(poiList);
        listView.setAdapter(adapter);

        final MaterialDialog dialog = new MaterialDialog(context, "本机地址:" + title, messageView);
        dialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.show();
        dialog.getButtonAccept().setText("确定");
        dialog.getButtonCancel().setText("取消");

        btnAll.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                for (int i = 0; i < poiList.size(); i++)
                {
                    MessageAdater.getIsSelected().put(i, true);
                }
                adapter.notifyDataSetChanged();
            }
        });

        btnCancel.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                for (int i = 0; i < poiList.size(); i++)
                {
                    MessageAdater.getIsSelected().put(i, false);
                }
                adapter.notifyDataSetChanged();
            }
        });

    }

    private void dataExportDialog()
    {
        List<String> cStyle = new ArrayList<String>();
        cStyle.add("当前工程管点导出");
        cStyle.add("当前工程管线导出");
        // cStyle.add("当前工程管沟点导出");
        View convertView = LayoutInflater.from(context).inflate(R.layout.dialog_listview, null);
        ListView styleList = (ListView) convertView.findViewById(R.id.dialogList);
        DialogAdapter dialogAdapter = new DialogAdapter(context);
        dialogAdapter.setList(cStyle);
        styleList.setAdapter(dialogAdapter);
        final MaterialDialog dialog = new MaterialDialog(context, convertView);
        dialog.show();
        final String dbName = ZSApplication.getInstance().getConfig("newDBName");

        styleList.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long lon)
            {
                if (0 == position)
                {
                    initPoints(dbName);
                    dialog.dismiss();
                }
                else if (1 == position)
                {
                    initLines(dbName);
                    dialog.dismiss();
                }
                // else if (2 == position)
                // {
                // dialog.dismiss();
                // }
            }
        });
    }

    /**
     * 
     * @Title: initData
     * @Description: TODO(导出数据)
     * @author fujianxiong
     * @throws
     */
    @SuppressLint("SimpleDateFormat")
    public void initPoints(String dbName)
    {
        String sql = "select * from " + "CMS_POINTS";
        file = new File(getSDPath() + "/Zyspps");
        makeDir(file);
        /*
         * File file1 = new File(file.toString() + "/" + dbName + "(管点)" +
         * ".xls"); if (file1.isFile() && file1.exists()) { file1.delete(); }
         */
        ExcelUtils.initExcel(file.toString() + "/" + dbName + "_管点" + ".xls", pointsTitle);
        ExcelUtils.writeObjListToExcel(getPointData(dbName, sql), getSDPath() + "/Zyspps" + "/" + dbName + "_管点" + ".xls", this);
    }

    public void initLines(String dbName)
    {
        String sql = "select * from " + "CMS_LINE";
        file = new File(getSDPath() + "/Zyspps");
        makeDir(file);
        /*
         * File file1 = new File(file.toString() + "/" + dbName + "(管线)" +
         * ".xls"); if (file1.isFile() && file1.exists()) { file1.delete(); }
         */
        ExcelUtils.initExcel(file.toString() + "/" + dbName + "_管线" + ".xls", linesTitle);
        ExcelUtils.writeObjListToExcel(getLinesData(dbName, sql), getSDPath() + "/Zyspps" + "/" + dbName + "_管线" + ".xls", this);
    }

    private ArrayList<ArrayList<String>> getPointData(String dbName, String sql)
    {
        pointList.clear();
        Cursor mCrusor = ZSApplication.getDaoSession(dbName).getCmsPointsDao().getDatabase().rawQuery(sql, null);
        while (mCrusor.moveToNext())
        {
            ArrayList<String> beanList = new ArrayList<String>();
            beanList.add(mCrusor.getString(1));
            beanList.add(mCrusor.getString(2));
            beanList.add(mCrusor.getString(3));
            beanList.add(mCrusor.getString(4));
            beanList.add(mCrusor.getString(5));
            beanList.add(mCrusor.getString(6));
            beanList.add(mCrusor.getString(7));
            beanList.add(mCrusor.getString(8));
            beanList.add(mCrusor.getString(9));
            beanList.add(mCrusor.getString(10));
            beanList.add(mCrusor.getString(11));
            beanList.add(mCrusor.getString(12));
            beanList.add(mCrusor.getString(13));
            beanList.add(mCrusor.getString(14));
            beanList.add(mCrusor.getString(15));
            beanList.add(mCrusor.getString(16));
            beanList.add(mCrusor.getString(17));
            beanList.add(mCrusor.getString(18));
            beanList.add(mCrusor.getString(19));
            beanList.add(mCrusor.getString(20));
            beanList.add(mCrusor.getString(21));
            beanList.add(mCrusor.getString(22));
            beanList.add(mCrusor.getString(23));
            beanList.add(mCrusor.getString(24));
            beanList.add(mCrusor.getString(25));
            beanList.add(mCrusor.getString(26));
            beanList.add(mCrusor.getString(27));
            beanList.add(mCrusor.getString(28));
            beanList.add(mCrusor.getString(29));
            beanList.add(mCrusor.getString(30));
            beanList.add(mCrusor.getString(31));
            beanList.add(mCrusor.getString(32));
            beanList.add(mCrusor.getString(33));
            beanList.add(mCrusor.getString(34));

            pointList.add(beanList);
        }
        mCrusor.close();
        return pointList;
    }

    private ArrayList<ArrayList<String>> getLinesData(String dbName, String sql)
    {
        lineList.clear();
        Cursor mCrusor = ZSApplication.getDaoSession(dbName).getCmsLineDao().getDatabase().rawQuery(sql, null);
        while (mCrusor.moveToNext())
        {
            ArrayList<String> beanList = new ArrayList<String>();
            beanList.add(mCrusor.getString(1));
            beanList.add(mCrusor.getString(2));
            beanList.add(mCrusor.getString(3));
            beanList.add(mCrusor.getString(4));
            beanList.add(mCrusor.getString(5));
            beanList.add(mCrusor.getString(6));
            beanList.add(mCrusor.getString(7));
            beanList.add(mCrusor.getString(8));
            beanList.add(mCrusor.getString(9));
            beanList.add(mCrusor.getString(10));
            beanList.add(mCrusor.getString(11));
            beanList.add(mCrusor.getString(12));
            beanList.add(mCrusor.getString(13));
            beanList.add(mCrusor.getString(14));
            beanList.add(mCrusor.getString(15));
            beanList.add(mCrusor.getString(16));
            beanList.add(mCrusor.getString(17));
            beanList.add(mCrusor.getString(18));
            beanList.add(mCrusor.getString(19));
            beanList.add(mCrusor.getString(20));
            beanList.add(mCrusor.getString(21));
            beanList.add(mCrusor.getString(22));
            beanList.add(mCrusor.getString(23));
            beanList.add(mCrusor.getString(24));
            beanList.add(mCrusor.getString(25));
            beanList.add(mCrusor.getString(26));
            beanList.add(mCrusor.getString(27));
            beanList.add(mCrusor.getString(28));
            beanList.add(mCrusor.getString(29));
            beanList.add(mCrusor.getString(30));
            beanList.add(mCrusor.getString(31));
            beanList.add(mCrusor.getString(32));
            beanList.add(mCrusor.getString(33));
            beanList.add(mCrusor.getString(34));
            beanList.add(mCrusor.getString(35));
            lineList.add(beanList);
        }
        mCrusor.close();
        return lineList;
    }

    public static void makeDir(File dir)
    {
        if (!dir.getParentFile().exists())
        {
            makeDir(dir.getParentFile());
        }
        dir.mkdir();
    }

    public String getSDPath()
    {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
        if (sdCardExist)
        {
            sdDir = Environment.getExternalStorageDirectory();
        }
        String dir = sdDir.toString();
        return dir;

    }

    private void saveCroppedImage(Bitmap bmp)
    {
        if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        {
            ToastUtil.show(context, "SDCard不存在~");
            return;
        }
        File file = new File("/sdcard/zysppsImg");
        if (!file.exists())
            file.mkdir();
        file = new File("/sdcard/zyspps.jpg".trim());
        String fileName = file.getName();
        String mName = fileName.substring(0, fileName.lastIndexOf("."));
        String sName = fileName.substring(fileName.lastIndexOf("."));
        String newFilePath = "/sdcard/zysppsImg" + "/" + mName + System.currentTimeMillis() + sName;
        file = new File(newFilePath);
        try
        {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bmp.compress(CompressFormat.JPEG, 50, fos);
            fos.flush();
            fos.close();
            ToastUtil.show(context, "截屏成功，请到/sdcard/zysppsImg文件夹下查看!");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // TODO Auto-generated method stub
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.option_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // TODO Auto-generated method stub
        switch (item.getItemId())
        {
        // 新建工程
        case R.id.option_create:
            String daName = ZSApplication.getInstance().getConfig("newDBName");
            if (StringUtil.isNotEmpty(daName))
            {
                ToastUtil.show(context, "请先关闭工程");
                break;
            }
            createProject();
            break;

        // 打开工程
        case R.id.option_open:
            String daName1 = ZSApplication.getInstance().getConfig("newDBName");
            if (StringUtil.isNotEmpty(daName1))
            {
                ToastUtil.show(context, "请先关闭工程");
                break;
            }
            openProject();
            break;

        // 关闭工程
        case R.id.option_close:
            isHasList.clear();
            aMap.clear();
            linePointList.clear();
            ZSApplication.getInstance().setConfig("newDBName", "");
            ZSApplication.getInstance().setConfig("isHasProject", "");
            break;

        // 查找点号
        case R.id.option_search:
            searchPoint();
            break;

        // 截屏
        case R.id.option_jieping:
            aMap.getMapScreenShot(this);

            // aMap.snapshot(new SnapshotReadyCallback()
            // {
            //
            // @Override
            // public void onSnapshotReady(Bitmap bitMap)
            // {
            // // TODO Auto-generated method stub
            // saveCroppedImage(bitMap);
            // }
            // });
            break;

        // 查找位置
        // case R.id.option_search_address:
        // break;

        // 关闭指北针
        case R.id.option_close_compass:
            String compass = ZSApplication.getInstance().getConfig("compass");
            if (StringUtil.isNotEmpty(compass))
            {
                ivCompass.setVisibility(View.GONE);
                ZSApplication.getInstance().setConfig("compass", "");
            }
            else
            {
                ivCompass.setVisibility(View.VISIBLE);
                ZSApplication.getInstance().setConfig("compass", "compass");
            }
            break;

        // 关闭背景地图
        case R.id.option_close_background_map:
            // String showMapBg =
            // ZSApplication.getInstance().getConfig("showMap");
            // if (StringUtil.isEmpty(showMapBg))
            // {
            // ZSApplication.getInstance().setConfig("showMap","closeMap");
            // ToastUtil.show(context, "背景地图已关闭，重启后生效~");
            // }else{
            // ZSApplication.getInstance().setConfig("showMap","");
            ToastUtil.show(context, "暂未开启");
            // }
            break;
        // 背景地图缓存
        case R.id.option_background_map_cache:

            break;

        // 清除背景地图缓存
        case R.id.option_clear_background_map:
        	getFileDir(getSDPath() + "/Zyspps");
            break;

        // 管线全部显示
        // case R.id.option_all_image_show:
        // break;
        // 数据导出
        case R.id.option_data_export:
            // dataExportDialog();
            if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            {
                ToastUtil.show(context, "SDCard不存在~");
                break;
            }
            exportProject();
            break;

        // 管线数量统计
        case R.id.option_point_statistics:
            boolean isTrue = isOpenProject();
            if (isTrue != true)
            {
                break;
            }
            IntentUtil.startActivity(PointNumCountActivity.class);
            break;

        // 坐标通讯
        // case R.id.option_coordinate_message:
        // break;

        // 设置
        case R.id.option_setting:
            IntentUtil.startActivity(SettingActivity.class);
            break;

        // 关于
        case R.id.option_about:
            break;

        default:
            break;
        }
        return false;
    }

    @Override
    public void onClick(View v)
    {
        // TODO Auto-generated method stub
        switch (v.getId())
        {
        case R.id.drawPan:
            ToastUtil.show(context, "拖拽");
            lllist.clear();
            drawPan.setBackgroundColor(getResources().getColor(R.color.red));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawLine.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawMove.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInsert.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInfo.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawDelete.setBackgroundColor(getResources().getColor(R.color.transparent2));
            setDrawPan();
            isDrawPan = true;
            isDrawPoint = false;
            isDrawLine = false;
            isDrawMove = false;
            isDrawInsert = false;
            isDrawInfo = false;
            isDrawDelete = false;
            break;
        case R.id.drawPoint:
            ToastUtil.show(context, "描点");
            lllist.clear();
            mUiSettings.setScrollGesturesEnabled(false);
            drawLine.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.red));
            drawPan.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawMove.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInsert.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInfo.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawDelete.setBackgroundColor(getResources().getColor(R.color.transparent2));
            isDrawPan = false;
            isDrawPoint = true;
            isDrawLine = false;
            isDrawMove = false;
            isDrawInsert = false;
            isDrawInfo = false;
            isDrawDelete = false;
            setMapMaker();
            break;
        case R.id.drawLine:
            ToastUtil.show(context, "画线");
            mUiSettings.setScrollGesturesEnabled(false);
            drawLine.setBackgroundColor(getResources().getColor(R.color.red));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPan.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawMove.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInsert.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInfo.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawDelete.setBackgroundColor(getResources().getColor(R.color.transparent2));
            isDrawPan = false;
            isDrawPoint = false;
            isDrawLine = true;
            isDrawMove = false;
            isDrawInsert = false;
            isDrawInfo = false;
            isDrawDelete = false;
            setMapLine();
            break;
        case R.id.drawMove:
            ToastUtil.show(context, "移动");
            lllist.clear();
            mUiSettings.setScrollGesturesEnabled(false);
            drawMove.setBackgroundColor(getResources().getColor(R.color.red));
            drawLine.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPan.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInsert.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInfo.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawDelete.setBackgroundColor(getResources().getColor(R.color.transparent2));
            movePoint();
            isDrawPan = false;
            isDrawPoint = false;
            isDrawLine = false;
            isDrawMove = true;
            isDrawInsert = false;
            isDrawInfo = false;
            isDrawDelete = false;
            break;
        case R.id.drawInsert:
            ToastUtil.show(context, "插入点");
            lllist.clear();
            mUiSettings.setScrollGesturesEnabled(false);
            drawInsert.setBackgroundColor(getResources().getColor(R.color.red));
            drawMove.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawLine.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPan.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInfo.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawDelete.setBackgroundColor(getResources().getColor(R.color.transparent2));
            isDrawPan = false;
            isDrawPoint = false;
            isDrawLine = false;
            isDrawMove = false;
            isDrawInsert = true;
            isDrawInfo = false;
            isDrawDelete = false;
             drawInsertPoint();
            break;
        case R.id.drawInfo:
            ToastUtil.show(context, "修改");
            lllist.clear();
            mUiSettings.setScrollGesturesEnabled(false);
            drawInfo.setBackgroundColor(getResources().getColor(R.color.red));
            drawInsert.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawMove.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawLine.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPan.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawDelete.setBackgroundColor(getResources().getColor(R.color.transparent2));
            updatePoint();
            isDrawPan = false;
            isDrawPoint = false;
            isDrawLine = false;
            isDrawMove = false;
            isDrawInsert = false;
            isDrawInfo = true;
            isDrawDelete = false;
            break;
        case R.id.drawDelete:
            ToastUtil.show(context, "删除");
            lllist.clear();
            mUiSettings.setScrollGesturesEnabled(false);
            drawDelete.setBackgroundColor(getResources().getColor(R.color.red));
            drawInfo.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawInsert.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawMove.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawLine.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPoint.setBackgroundColor(getResources().getColor(R.color.transparent2));
            drawPan.setBackgroundColor(getResources().getColor(R.color.transparent2));
            isDrawPan = false;
            isDrawPoint = false;
            isDrawLine = false;
            isDrawMove = false;
            isDrawInsert = false;
            isDrawInfo = false;
            isDrawDelete = true;
            removePoint();
            break;
        case R.id.showTypeBtn:
            String daName = ZSApplication.getInstance().getConfig("newDBName");
            if (StringUtil.isEmpty(daName))
            {
                ToastUtil.show(context, "请先打开工程");
                break;
            }
            showTypeDialog(showTypeBtn.getText().toString());
            break;
        case R.id.showTypeBigBtn:
        	String daName1 = ZSApplication.getInstance().getConfig("newDBName");
            if (StringUtil.isEmpty(daName1))
            {
                ToastUtil.show(context, "请先打开工程");
                break;
            }
            List<CmsPointsName> list = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().orderAsc(com.gesee.zyspps.db.CmsPointsNameDao.Properties.Sort).list();
            List bigtList = new ArrayList();
            bigtList.add("全部");
            for (int i = 0; i < list.size(); i++)
            {
                int a = 0;
                if (bigtList != null && bigtList.size() > 0)
                {
                    for (int j = 0; j < bigtList.size(); j++)
                    {

                        if (bigtList.get(j).toString().equals(list.get(i).getParCode()))
                        {
                            break;
                        }
                        else
                        {
                            a = a + 1;
                        }
                    }
                }

                if (a == bigtList.size())
                {
                    bigtList.add(list.get(i).getParCode());
                }

            }
            
            showTypeBigDialog(bigtList);	
        	break;

        default:
            break;
        }
    }
    
    /**
     * 
     * @Title: showTypeDialog
     * @Description: TODO(选择显示的小类)
     * @author fujianxiong
     * @throws
     */
    private void showTypeBigDialog(final List list)
    {
        final String daName = ZSApplication.getInstance().getConfig("newDBName");
        View typeView = LayoutInflater.from(context).inflate(R.layout.open_project_dialog, null);
        final MyListView listView = (MyListView) typeView.findViewById(R.id.listView);
        //final TextView tv_type = (TextView) typeView.findViewById(R.id.tv_type);
        //final MyListView listViewBig = (MyListView) typeView.findViewById(R.id.listViewBig);
        //tv_type.setText(typename);
        
        ShowBigTypeAdater adapter = new ShowBigTypeAdater(context,selectMap);
        adapter.setList(list);
        listView.setAdapter(adapter);
       // listViewBig.setAdapter(adapter);
        
        if (typeBigDialog != null)
        {
        	typeBigDialog.cancel();
        }
        
        typeBigDialog = new MaterialDialog(context, typeView);

        typeBigDialog.show();
        
        
        listView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
            	// 根据大类去获取小类数据
            	String name = list.get(position).toString();
            	List<CmsPoints> pointList = new ArrayList<CmsPoints>();
                List<CmsLine> lineList = new ArrayList<CmsLine>();
                List<CmsSpecialLine> cmsSpecialLinelist = new ArrayList<CmsSpecialLine>();
                //List<CmsPoints> pointList = ZSApplication.getDaoSession(daName).getCmsPointsDao().queryBuilder().where(Properties.PCode.eq(name)).build().list();
                List<CmsPoints> pointAllList = ZSApplication.getDaoSession(daName).getCmsPointsDao().loadAll();
                //List<CmsLine> lineList = ZSApplication.getDaoSession(daName).getCmsLineDao().queryBuilder().where(com.gesee.zyspps.db.CmsLineDao.Properties.PCode.eq(name)).build().list();
                List<CmsLine> lineAllList = ZSApplication.getDaoSession(daName).getCmsLineDao().loadAll();

               /* List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.PCode.eq(name)).build().list();*/
                List<CmsSpecialLine> cmsSpecialLineAlllist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().loadAll();
               // CheckBox ck = (CheckBox) view.findViewById(R.id.ckbox);
                isHasList.clear();
                aMap.clear();
                linePointList.clear();
            	if(position!=0){
            		showTypeBtn.setEnabled(true);
            		
            		if(selectMap.containsKey(name)){
                		selectMap.remove(name);
                		//ck.setChecked(false);
                    }else{
                    	
                    	//View v = listView.getChildAt(0);
                    	//CheckBox ck1 = (CheckBox) v.findViewById(R.id.ckbox);
                    	//ck1.setChecked(false);
                    	//ck.setChecked(true);
                    }
            		
            		samllList = new ArrayList();
            		List<CmsPointsName> smalllist = ZSApplication.getDaoSession("zyspps-db").getCmsPointsNameDao().queryBuilder().where(com.gesee.zyspps.db.CmsPointsNameDao.Properties.ParCode.eq(name)).list();
            		if(smalllist!=null&&smalllist.size()>0){
            			for(int i = 0 ; i < smalllist.size();i++){
            				samllList.add(smalllist.get(i).getSubCode());
            			}
            		}
            		
            		
            		if(selectMap!=null&&selectMap.size()>0){
            			for(String key : selectMap.keySet()){
            				List<CmsPoints> pList = ZSApplication.getDaoSession(daName).getCmsPointsDao().queryBuilder().where(Properties.PCode.eq(key)).build().list();
            				List<CmsLine> lList = ZSApplication.getDaoSession(daName).getCmsLineDao().queryBuilder().where(com.gesee.zyspps.db.CmsLineDao.Properties.PCode.eq(key)).build().list();
            				List<CmsSpecialLine> slist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().queryBuilder()
                                    .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.PCode.eq(key)).build().list();
            				pointList.addAll(pList);
            				lineList.addAll(lList);
            				cmsSpecialLinelist.addAll(slist);
            			}
            			loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
            		}
            	}else{
            		showTypeBtn.setEnabled(false);
            		if(list.get(position).toString().equals("全部")){
                    	if(selectMap.containsKey("ALL")){
                    		selectMap.remove("ALL");
                    		//ck.setChecked(false);
                        }else{
                        	selectMap.clear();
                        	selectMap.put("ALL","全部");
                        //	ck.setChecked(true);
                        	loadPointOrLine(pointAllList, lineAllList, cmsSpecialLineAlllist);
                        }
                	}
            	}
                
                
            	typeBigDialog.dismiss();
            }
        });
    }
    

    /**
     * 
     * @Title: showTypeDialog
     * @Description: TODO(选择显示的小类)
     * @author fujianxiong
     * @throws
     */
    private void showTypeDialog(String typename)
    {
        final String daName = ZSApplication.getInstance().getConfig("newDBName");
        View typeView = LayoutInflater.from(context).inflate(R.layout.open_project_dialog, null);
        final MyListView listView = (MyListView) typeView.findViewById(R.id.listView);
        //final TextView tv_type = (TextView) typeView.findViewById(R.id.tv_type);
        //final MyListView listViewBig = (MyListView) typeView.findViewById(R.id.listViewBig);
        //tv_type.setText(typename);
        
        ShowTypeAdater adapter = new ShowTypeAdater(context,selectMap);
        adapter.setList(samllList);
        listView.setAdapter(adapter);
       // listViewBig.setAdapter(adapter);
        
        if (typeDialog != null)
        {
            typeDialog.cancel();
        }
        
        typeDialog = new MaterialDialog(context, typeView);

        typeDialog.show();
        
        
        listView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                String name = samllList.get(position).toString();
                List<CmsPoints> pointList = new ArrayList<CmsPoints>();
                List<CmsLine> lineList = new ArrayList<CmsLine>();
                List<CmsSpecialLine> cmsSpecialLinelist = new ArrayList<CmsSpecialLine>();
                //List<CmsPoints> pointList = ZSApplication.getDaoSession(daName).getCmsPointsDao().queryBuilder().where(Properties.PCode.eq(name)).build().list();
                List<CmsPoints> pointAllList = ZSApplication.getDaoSession(daName).getCmsPointsDao().loadAll();
                //List<CmsLine> lineList = ZSApplication.getDaoSession(daName).getCmsLineDao().queryBuilder().where(com.gesee.zyspps.db.CmsLineDao.Properties.PCode.eq(name)).build().list();
                List<CmsLine> lineAllList = ZSApplication.getDaoSession(daName).getCmsLineDao().loadAll();

               /* List<CmsSpecialLine> cmsSpecialLinelist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().queryBuilder()
                        .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.PCode.eq(name)).build().list();*/
                List<CmsSpecialLine> cmsSpecialLineAlllist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().loadAll();
                CheckBox ck = (CheckBox) view.findViewById(R.id.ckbox);
                isHasList.clear();
                aMap.clear();
                linePointList.clear();
                
               /* if(setList.get(position).toString().equals("全部")){
                	if(selectMap.containsKey("ALL")){
                		selectMap.remove("ALL");
                		ck.setChecked(false);
                    }else{
                    	selectMap.clear();
                    	selectMap.put("ALL","全部");
                    	ck.setChecked(true);
                    	loadPointOrLine(pointAllList, lineAllList, cmsSpecialLineAlllist);
                    }
            	}else{*/
            		if(selectMap.containsKey(name)){
                		selectMap.remove(name);
                		ck.setChecked(false);
                    }else{
                    	selectMap.put(name,name);
                    	selectMap.remove("ALL");
                    	View v = listView.getChildAt(0);
                    	CheckBox ck1 = (CheckBox) v.findViewById(R.id.ckbox);
                    	ck1.setChecked(false);
                    	ck.setChecked(true);
                    }
            		if(selectMap!=null&&selectMap.size()>0){
            			for(String key : selectMap.keySet()){
            				List<CmsPoints> pList = ZSApplication.getDaoSession(daName).getCmsPointsDao().queryBuilder().where(Properties.PCode.eq(key)).build().list();
            				List<CmsLine> lList = ZSApplication.getDaoSession(daName).getCmsLineDao().queryBuilder().where(com.gesee.zyspps.db.CmsLineDao.Properties.PCode.eq(key)).build().list();
            				List<CmsSpecialLine> slist = ZSApplication.getDaoSession(daName).getCmsSpecialLineDao().queryBuilder()
                                    .where(com.gesee.zyspps.db.CmsSpecialLineDao.Properties.PCode.eq(key)).build().list();
            				pointList.addAll(pList);
            				lineList.addAll(lList);
            				cmsSpecialLinelist.addAll(slist);
            			}
            			loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
            		}
            		
            	//}
                
                /*if ("全部".equals(name))
                {
                    showTypeBtn.setText("当前：全部");
//                    tv_type.setText("当前：全部");
                    loadPointOrLine(pointAllList, lineAllList, cmsSpecialLineAlllist);
                }
                else
                {
                    showTypeBtn.setText("当前："+ name);
//                    tv_type.setText("当前："+name);
                    loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
                }*/
                /*if(position == 0){
                	 showTypeBtn.setText("当前：全部");
//                   tv_type.setText("当前：全部");
                   loadPointOrLine(pointAllList, lineAllList, cmsSpecialLineAlllist);
                }else{
                	loadPointOrLine(pointList, lineList, cmsSpecialLinelist);
                }*/
                //typeDialog.dismiss();
            }
        });
    }

    @Override
    protected void onResume()
    {
        mapView.onResume();
        isOpenProject();
        lllist.clear();
        String mapCurrentName = ZSApplication.getInstance().getConfig("mapCurrentName");
        String mapCurrentD_X = ZSApplication.getInstance().getConfig("mapCurrentD_X");
        String mapCurrentD_Y = ZSApplication.getInstance().getConfig("mapCurrentD_Y");
        String startPoint = ZSApplication.getInstance().getConfig("startPoint");
        String endPoint = ZSApplication.getInstance().getConfig("endPoint");
        
        String needDeleteSpeciaLine = ZSApplication.getInstance().getConfig("needDeleteSpeciaLine");
        String delSp = ZSApplication.getInstance().getConfig("delSp");
        
        if ("yes".equals(delSp))
        {
            lllist.clear();
            isHasList.clear();
            aMap.clear();
            linePointList.clear();
        }
        if ("true".equals(needDeleteSpeciaLine))
        {
            lllist.clear();
            isHasList.clear();
            aMap.clear();
            linePointList.clear();
        }
        
        if (StringUtil.isNotEmpty(mapCurrentD_X) && StringUtil.isNotEmpty(mapCurrentD_Y))
        {
            setMaker(Double.parseDouble(mapCurrentD_X), Double.parseDouble(mapCurrentD_Y), mapCurrentName);
        }
        if (StringUtil.isNotEmpty(startPoint) && StringUtil.isNotEmpty(endPoint))
        {
            setLine(startPoint, endPoint);
        }
        super.onResume();
    }

    public void mapsetting(View v)
    {
        mapsettingDialog();
    }

    private void mapsettingDialog()
    {
        View stView = LayoutInflater.from(context).inflate(R.layout.map_setting_dialog, null);

        Button btnAll = (Button) stView.findViewById(R.id.btnAll);
        Button btnCancel = (Button) stView.findViewById(R.id.btnCancel);
        final CheckBox cbMap = (CheckBox) stView.findViewById(R.id.cbMap);
        final CheckBox cbGPS = (CheckBox) stView.findViewById(R.id.cbGPS);

        final MaterialDialog dialog = new MaterialDialog(context, "图层", stView);
        dialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.show();
        dialog.getButtonAccept().setText("确定");
        dialog.getButtonCancel().setText("取消");

        btnAll.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                cbMap.setChecked(true);
                cbGPS.setChecked(true);
            }
        });

        btnCancel.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                cbMap.setChecked(false);
                cbGPS.setChecked(false);
            }
        });

    }

    private boolean isOpenProject()
    {
        boolean isProject = false;
        String isOpenProject = ZSApplication.getInstance().getConfig("isHasProject");
        if (StringUtil.isEmpty(isOpenProject))
        {
            isProject = false;
            ToastUtil.show(context, "请打开或新建工程");
        }
        else
        {
            isProject = true;
        }
        return isProject;
    }

    private void closeProjectDialog()
    {
        final MaterialDialog dialog = new MaterialDialog(context, "退出程序", "确认退出系统？");
        dialog.setOnAcceptButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                isHasList.clear();
                aMap.clear();
                linePointList.clear();
                ZSApplication.getInstance().setConfig("newDBName", "");
                ZSApplication.getInstance().setConfig("isHasProject", "");
                ZSApplication.getInstance().finishAllActivity();
                dialog.dismiss();
            }
        });
        dialog.setOnCancelButtonClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                dialog.dismiss();
            }
        });
        dialog.show();
        dialog.getButtonAccept().setText("确定");
        dialog.getButtonCancel().setText("取消");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        // TODO Auto-generated method stub

        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            closeProjectDialog();
        }
        return false;
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause()
    {
        super.onPause();
        mapView.onPause();
        deactivate();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        mapView.onDestroy();
        isHasList.clear();
        aMap.clear();
        linePointList.clear();
        ZSApplication.getInstance().setConfig("newDBName", "");
        ZSApplication.getInstance().setConfig("isHasProject", "");
        ZSApplication.getInstance().finishAllActivity();
    }

    /**
     * 定位成功后回调函数
     */
    @Override
    public void onLocationChanged(AMapLocation amapLocation)
    {
        if (mListener != null && amapLocation != null)
        {
            if (amapLocation != null && amapLocation.getErrorCode() == 0)
            {
                mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
            }
            else
            {
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
                Log.e("AmapErr", errText);
            }
        }
    }

    /**
     * 激活定位
     */
    @Override
    public void activate(OnLocationChangedListener listener)
    {
        mListener = listener;
        if (mlocationClient == null)
        {
            mlocationClient = new AMapLocationClient(this);
            mLocationOption = new AMapLocationClientOption();
            // 设置定位监听
            mlocationClient.setLocationListener(this);
            // 设置为高精度定位模式
            mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
            // 设置定位参数
            mlocationClient.setLocationOption(mLocationOption);
            // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
            // 注意设置合适的定位时间的间隔（最小间隔支持为2000ms），并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后，在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
            mlocationClient.startLocation();
        }
    }

    /**
     * 停止定位
     */
    @Override
    public void deactivate()
    {
        mListener = null;
        if (mlocationClient != null)
        {
            mlocationClient.stopLocation();
            mlocationClient.onDestroy();
        }
        mlocationClient = null;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev)
    {
        // if (!isDrawLine||!isDrawInsert)
        // {
        // return super.dispatchTouchEvent(ev);
        // }
        switch (ev.getAction())
        {

        case MotionEvent.ACTION_DOWN:
            Log.e("开始:", "");
            if (isDrawLine)
            {
                LogUtil.e("画线");
                ev.setAction(MotionEvent.ACTION_DOWN);
                super.dispatchTouchEvent(ev);
                ev.setAction(MotionEvent.ACTION_UP);
                super.dispatchTouchEvent(ev);
            }
            else if (isDrawInsert)
            {
                LogUtil.e("插入点");
                ev.setAction(MotionEvent.ACTION_DOWN);
                super.dispatchTouchEvent(ev);
            }
            // else if (isDrawDelete)
            // {
            // LogUtil.e("删除点线");
            // ev.setAction(MotionEvent.ACTION_DOWN);
            // super.dispatchTouchEvent(ev);
            // }
            break;
        case MotionEvent.ACTION_MOVE:
            Log.e("移动:", "");
            break;
        case MotionEvent.ACTION_UP:
            Log.e("结束:", "");

            if (isDrawLine)
            {
                LogUtil.e("画线结束");
                ev.setAction(MotionEvent.ACTION_DOWN);
                super.dispatchTouchEvent(ev);
                ev.setAction(MotionEvent.ACTION_UP);
                super.dispatchTouchEvent(ev);
            }
//            else if (isDrawInsert)
//            {
//                LogUtil.e("x=" + ev.getX() + "y=" + ev.getY());
//                int statusHeight = Utils.getStatusHeight(this);
//
//                int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
//                int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
//                spinner.measure(w, h); // 测量spinner的高度
//                int height = spinner.getMeasuredHeight();
//
//                LatLng latlng = aMap.getProjection().fromScreenLocation(new Point((int) ev.getX(), (int) ev.getY() - statusHeight - height));
//                double lat = latlng.latitude;
//                double lng = latlng.longitude;
//
//                LogUtil.e("latitude=" + lat + "longitude=" + lng);
//                drawInsertPoint(lat, lng);
//
//                LogUtil.e("插入点结束");
//                ev.setAction(MotionEvent.ACTION_UP);
//                super.dispatchTouchEvent(ev);
//            }
            // else if (isDrawDelete)
            // {
            // LogUtil.e("x=" + ev.getX() + "y=" + ev.getY());
            // int statusHeight = Utils.getStatusHeight(this);
            //
            // int w = View.MeasureSpec.makeMeasureSpec(0,
            // View.MeasureSpec.UNSPECIFIED);
            // int h = View.MeasureSpec.makeMeasureSpec(0,
            // View.MeasureSpec.UNSPECIFIED);
            // spinner.measure(w, h); // 测量spinner的高度
            // int height = spinner.getMeasuredHeight();
            //
            // LatLng latlng = aMap.getProjection().fromScreenLocation(new
            // Point((int) ev.getX(), (int) ev.getY() - statusHeight - height));
            // double lat = latlng.latitude;
            // double lng = latlng.longitude;
            //
            // LogUtil.e("latitude=" + lat + "longitude=" + lng);
            // // drawInsertPoint(lat, lng);
            // removePoint(lat, lng);
            // LogUtil.e("删除点线结束");
            // ev.setAction(MotionEvent.ACTION_UP);
            // super.dispatchTouchEvent(ev);
            // }
            break;

        default:
            break;
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public void onMapScreenShot(Bitmap bitmap)
    {
        if (null == bitmap)
        {
            return;
        }
        if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        {
            ToastUtil.show(context, "SDCard不存在~");
            return;
        }
        File file = new File("/sdcard/zysppsImg");
        if (!file.exists())
            file.mkdir();
        file = new File("/sdcard/zyspps.png".trim());
        String fileName = file.getName();
        String mName = fileName.substring(0, fileName.lastIndexOf("."));
        String sName = fileName.substring(fileName.lastIndexOf("."));
        String newFilePath = "/sdcard/zysppsImg" + "/" + mName + System.currentTimeMillis() + sName;
        file = new File(newFilePath);
        try
        {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(CompressFormat.PNG, 50, fos);
            fos.flush();
            fos.close();
            ToastUtil.show(context, "截屏成功，请到/sdcard/zysppsImg文件夹下查看!");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
    
    /**
     * 
    * @Title: getFileDir
    * @Description: TODO(查询所有文件。)
    * @author fujianxiong
    * @param filePath
    * @throws
     */
    private void getFileDir(String filePath) {
         Map<String,String> fileNameMap = new HashMap<String, String>();
        List<CmsDbNum> items = new ArrayList<CmsDbNum>();
        File file = new File(filePath);
        File[] files = file.listFiles();
        if (files.length <= 0)
        {
            ToastUtil.show(context, "没有可导入的项目。");
            return;
        }
        for(File fileTemp :files) {
            CmsDbNum db = new CmsDbNum();
            
            String dbs[] = fileTemp.getName().split("_");
            String daName = dbs[0];
            db.setDbName(daName);
            if(!fileNameMap.containsKey(daName)){
            	items.add(db);
            	fileNameMap.put(daName, daName);
            }
            
        }
         
        leadInProject(items);
         
    }
    
    /**
     * 
    * @Title: leadInProject
    * @Description: TODO(导入)
    * @author fujianxiong
    * @param dbList
    * @throws
     */
    private void leadInProject(final List<CmsDbNum> dbList)
    {
        View openProjectView = LayoutInflater.from(context).inflate(R.layout.open_project_dialog, null);
        final MyListView listView = (MyListView) openProjectView.findViewById(R.id.listView);

        adapter = new ExistenceProjectAdater(context);
        adapter.setList(dbList);
        listView.setAdapter(adapter);

        final MaterialDialog dialog = new MaterialDialog(context, "可以导入的项目名", openProjectView);
        dialog.show();
        dialog.getButtonAccept().setVisibility(View.GONE);
        dialog.getButtonCancel().setVisibility(View.GONE);

        listView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                // TODO Auto-generated method stub
                String daName = dbList.get(position).getDbName();
                final List<CmsDbNum> dbNumList = ZSApplication.getDaoSession("zyspps-db").getCmsDbNumDao().loadAll();
                //String dbs[] = dataname.split("_");
                //String daName = dbs[0];
                int result = 0;
                for (int i = 0; i < dbNumList.size(); i++)
                {
                    if (daName.equals(dbNumList.get(i).getDbName()))
                    {
                        ToastUtil.show(context, "已成功导入过,或者已经存在该项目名称。");
                        //return;
                        result = 1;
                    }
                }
                
                if (StringUtil.isEmpty(daName))
                {
                    ToastUtil.show(context, "项目名不能为空~");
                    return;
                }
                if(result != 1){
                	CmsDbNum dbNum = new CmsDbNum();
                    dbNum.setDbName(daName);
                    ZSApplication.getDaoSession(daName);
                    ZSApplication.getDaoSession().getCmsDbNumDao().insert(dbNum);
                    ZSApplication.getInstance().setConfig("newDBName", daName);
                    
                    /*if(dataname.indexOf("管点")!=-1){
                        ExcelUtils.readPointExcel(getSDPath() + "/Zyspps/"+ daName +"_管点.xls");
                        ExcelUtils.readLineExcel(getSDPath() + "/Zyspps/"+ daName +"_管线.xls");
                        ToastUtil.show(context, "请手动打开工程" + daName);
                    }*/
                   // if(dataname.indexOf("管线")!=-1){
                        ExcelUtils.readPointExcel(getSDPath() + "/Zyspps/"+ daName +"_管点.xls");
                        ExcelUtils.readLineExcel(getSDPath() + "/Zyspps/"+ daName +"_管线.xls");
                        ToastUtil.show(context, "请手动打开工程" + daName);
                   // }
                }
                
                dialog.dismiss();
            }
        });
    }

}